{"id":216,"date":"2023-08-16T12:27:42","date_gmt":"2023-08-16T04:27:42","guid":{"rendered":"http:\/\/ggapa.net:81\/?p=216"},"modified":"2024-02-09T20:44:42","modified_gmt":"2024-02-09T12:44:42","slug":"oi%e5%ad%a6%e4%b9%a0-%e6%95%b0%e5%ad%a6","status":"publish","type":"post","link":"http:\/\/ggapa.net:81\/2023\/08\/16\/oi%e5%ad%a6%e4%b9%a0-%e6%95%b0%e5%ad%a6\/","title":{"rendered":"\u6570\u8bba\u76f8\u5173\u77e5\u8bc6"},"content":{"rendered":"
\u6ce8\uff1a\u8fdc\u53e4\u4f5c\u54c1\uff0c\u5199\u7684\u5f88\u5783\u573e<\/strong><\/p>\n \u901a\u8fc7\u7ed9\u4e0a\u9762\u7684\u4ee3\u7801\u6dfb\u52a0\u4e00\u70b9\u5c0f\u5c0f\u7684\u4fee\u6539\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u5f97\u5230\u4e86\u4e00\u4e2a\u65e2\u80fd\u7b5b\u8d28\u6570\uff0c\u4e5f\u80fd\u5206\u89e3\u8d28\u56e0\u5b50\u7684\u51fd\u6570<\/p>\n \u7ed9\u5b9a\u4e00\u4e2a\u6570\u7136\u540e\u6c42\u51fa\u5b83\u6240\u6709\u7684\u8d28\u56e0\u5b50\u3002<\/p>\n \u8fd9\u4e48\u505a\u4e00\u5b9a\u662f\u53ef\u884c\u7684\uff0c\u5229\u7528\u4e86 \u4ed6\u7684\u66f4\u591a\u6269\u5c55\u7528\u6cd5\uff1a<\/p>\n $pri_i$\uff1a \u7f16\u53f7\u4e3a $i$ \u7684\u8d28\u6570\u3002<\/p>\n $mi_i$ \uff1a$i$ \u7684\u6700\u5c0f\u8d28\u56e0\u5b50\u3002<\/p>\n $phi_i$\uff1a $\\varphi(i)$ \u7684\u503c\uff08\u6b27\u62c9\u51fd\u6570\uff09\u3002<\/p>\n $mu_i$\uff1a$\\mu(i)$ \u7684\u503c\uff08\u83ab\u6bd4\u4e4c\u65af\u51fd\u6570\uff09\u3002<\/p>\n \u5f53\u7136\uff0c\u7b5b\u6cd5\u8fd8\u80fd\u6709\u66f4\u591a\u7684\u5e94\u7528\uff0c\u4ed6\u8fd8\u80fd\u5728\u56e0\u5b50\u4e0a\u4e0b\u529f\u592b\u3002<\/p>\n $$n = \\prod_{i=1}^{m} p_{i}^{k_i}$$<\/p>\n \u8bbe\u6709\u4e24\u4e2a\u6570\uff1a$a = \\prod_{i=1}^{m_a} pa_{i}^{ka_i}$ \u3001$b = \\prod_{i=1}^{m_b} pb_{i}^{kb_i}$\uff0c\u5219\u6709\uff1a<\/p>\n \u5b83\u4eec\u7684 $\\gcd$ \u4e3a\u4e8c\u8005 $k$ \u53d6 $\\min$ \uff0c\u800c $lcm$ \u4e3a\u4e8c\u8005\u7684 $k$ \u53d6 $\\max$<\/p>\n \u7531\u7b97\u6570\u57fa\u672c\u5b9a\u7406\u53ef\u5f97\uff0c\u4e00\u4e2a\u6570 $n$ \u4e00\u5b9a\u53ef\u4ee5\u88ab\u4ee5\u4e0b\u7684\u5f0f\u5b50\u8868\u793a\u51fa\u6765\uff1a<\/p>\n $$n = \\prod_{i=1}^{m} p_{i}^{k_i}$$<\/p>\n \u540e\u6587\u4e2d\u9ed8\u8ba4 $p$ \u4ece\u5c0f\u5230\u5927\u6392\u5e8f\u5e76\u7f16\u53f7 $$\\sum_{d|n}^{}d $$ <\/p>\n \u901a\u8fc7\u4e00\u7cfb\u5217\u7684\u63a8\u5230\u53ef\u4ee5\u5f97\u51fa<\/p>\n $$\\sum_{d|n}^{}d = \\prod_{i=1}^{m} \\sum_{j=0}^{k_i} p_i^j$$<\/p>\n \u63a8\u5230\u8fc7\u7a0b\u5982\u4e0b\uff1a<\/p>\n \u5bf9\u4e8e\u6bcf\u4e00\u4e2a\u8d28\u6570 $p_i$ \u4ed6\u7684\u4e0d\u540c\u6b21\u65b9\u53ef\u4ee5\u6784\u6210\u4e00\u4e2a\u96c6\u5408\uff0c\u7b14\u8005\u62ff $360$ \u6765\u4e3e\u4f8b\uff1a<\/p>\n \u5df2\u77e5 :<\/p>\n $$360 = 2^3\\cdot3^2 \\cdot5^1$$<\/p>\n $360$ \u88ab\u5206\u89e3\u6210\u4e86\u4e09\u4e2a\u8d28\u6570\uff0c\u90a3\u4e48\u5176\u6240\u6709\u7684\u56e0\u6570\u90fd\u80fd\u901a\u8fc7\u8fd9\u4e09\u4e2a\u8d28\u6570\u4e0d\u540c\u6b21\u5e42\u7684\u4e58\u79ef\u8868\u793a\u3002\u4f8b\u5982 $2^1\\cdot3^0 \\cdot5^0$\uff0c$2^1\\cdot3^0 \\cdot5^1$\uff0c$2^2\\cdot3^1 \\cdot5^0$ \uff0c\u7b49\u7b49\u3002\u50cf\u8fd9\u6837\u7684\u6570\uff0c\u90fd\u662f $360$ \u7684\u56e0\u6570\u3002<\/p>\n \u5176\u56e0\u6570\u548c\u7b49\u4e8e\uff1a<\/p>\n $$2^0 \\cdot 3^0 \\cdot 5^0 + 2^0 \\cdot 3^0 \\cdot 5^1 + 2^0 \\cdot 3^1 \\cdot 5^0 + 2^0 \\cdot 3^1 \\cdot 5^1 + 2^0 \\cdot 3^2 \\cdot 5^0+ \\cdots + 2^3 \\cdot 3^2 \\cdot 5^1$$<\/p>\n \u5316\u7b80\u53ef\u5f97\uff1a<\/p>\n $$(1 + 2^1 + 2^2 + 2^3)\\cdot(1+3^1+3^2) \\cdot (1+5^1) = \\prod_{i=1}^{3} \\sum_{j=0}^{k_i} {p_i}^j $$<\/p>\n \u63a8\u5bfc\u5b8c\u6bd5\u3002<\/p>\n \u95ee\u9898\u63cf\u8ff0<\/strong><\/p>\n \u7ed9\u5b9a\u4e00\u4e2a\u6570 $n$ \u6c42 $[1,n]$ \u4e2d\u6240\u6709\u6570\u7684\u56e0\u5b50\u548c\u3002<\/p>\n \u5206\u6790\u4e0e\u89e3\u7b54<\/strong><\/p>\n \u4e3a\u4e86\u5728 $O(n)$ \u7684\u65f6\u95f4\u590d\u6742\u5ea6\u5185\u89e3\u51b3\u95ee\u9898\uff0c\u4e0a\u8ff0\u9898\u76ee\u53ef\u4ee5\u901a\u8fc7\u7ebf\u6027\u7b5b\u6765\u89e3\u51b3\uff1b<\/p>\n \u6211\u4eec\u5b9a\u4e49 $f_i$\uff0c\u4ee3\u8868 $i$ \u7684\u56e0\u5b50\u548c\u3002<\/p>\n \u5b9a\u4e49 $g_i$ \u4ee3\u8868\uff1a<\/p>\n $$\\sum_{j=0}^{k_1} {p_1}^j$$<\/p>\n \u6211\u4eec\u8be5\u5982\u4f55\u5904\u7406\u8fd9\u4e24\u4e2a\u6570\u7ec4\uff1f<\/p>\n \u5bf9\u4e8e\u6bcf\u6b21\u5faa\u73af\u5f97\u5230\u7684 $i$\uff0c\u82e5 $i$ \u662f\u8d28\u6570\uff08\u60c5\u51b5\u4e00\uff09\uff0c$f_i = i + 1$ \uff0c$g_i = i + 1$\u3002\u4e0d\u505a\u8fc7\u591a\u8d58\u8ff0\u3002<\/p>\n \u5426\u5219\uff0c\u6211\u4eec\u5df2\u7ecf\u77e5\u9053\u4e86 $i$ \u7684\u552f\u4e00\u5206\u89e3\u5f0f\uff0c\u6709\u4e24\u79cd\u60c5\u51b5\u9700\u8981\u6211\u4eec\u8003\u8651\uff1a<\/p>\n \u5b9a\u4e49 $t = i\\times prime_j$<\/p>\n \u5219 $g_t = prime_j+1$\uff0c $f_t = f_i \\times g_t$\u3002<\/p>\n \u4e3e\u4e00\u4e2a\u4f8b\u5b50\uff1a<\/p>\n \u82e5\u6b64\u65f6 $i$ \u7684\u552f\u4e00\u5206\u89e3\u5f0f\u4e3a $3^2\\cdot5^1$\uff0c$prime_j=2$\uff0c\u6ee1\u8db3\u60c5\u51b5\u4e8c\u3002\u6b64\u65f6 $t$ \u7684\u552f\u4e00\u5206\u89e3\u5f0f\u4e3a $3^3\\cdot4^1$\uff0c $g_i = 1+3^1+3^2$\uff0c$f_i = (1+3^1+3^2)\\times(1+5^1)$\u3002<\/p>\n \u7ecf\u8fc7\u63a8\u5bfc\u53ef\u77e5\uff1a<\/p>\n $$g_t = 1 + 2 = 1 + prime_j$$<\/p>\n $$ f_t = (1+2^1)\\times(1+3^1+3^2)\\times(1+5^1) = g_t\\times f_i$$<\/p>\n \u5219 $g_t = g_i \\times prime_j + 1$\uff0c $f_t = \\frac{f_i \\times g_t}{g_i}$<\/p>\n \u4e3e\u4e00\u4e2a\u4f8b\u5b50\uff1a<\/p>\n \u82e5\u6b64\u65f6 $i$ \u7684\u552f\u4e00\u5206\u89e3\u5f0f\u4e3a $2^2\\cdot3^1$\uff0c$prime_j=2$\uff0c\u6ee1\u8db3\u60c5\u51b5\u4e09\u3002\u6b64\u65f6 $t$ \u7684\u552f\u4e00\u5206\u89e3\u5f0f\u4e3a $2^3\\cdot3^1$\uff0c $g_i = 1+2^1+2^2$\uff0c$f_i = (1+2^1+2^2)\\times(1+3^1)$\u3002<\/p>\n \u7ecf\u8fc7\u63a8\u5bfc\u53ef\u77e5\uff1a<\/p>\n $$g_t = 1+2^1+2^2+2^3=(1+2^1+2^2)\\times2+1=g_i\\cdot prime_j+1$$<\/p>\n $$f_t= (1+2^1+2^2+2^3)\\times(1+3^1) = \\frac{(1+2^1+2^2)\\times(1+3^1)}{(1+2^1+2^2)}\\times (1+2^1+2^2+2^3) =\\frac{f_i }{g_i}\\times g_t$$<\/p>\n \u5f62\u5982 $ax + by = c$\uff0c\u5176\u4e2d $a, b, c$ \u662f\u5df2\u77e5\u6570\u7684\u65b9\u7a0b\u88ab\u79f0\u4e3a\u4e8c\u5143\u4e00\u6b21\u4e0d\u5b9a\u65b9\u7a0b\u3002<\/p>\n \u5b9a\u7406<\/strong>\uff1a\u65b9\u7a0b $ax + by = c$ \u6709\u89e3\u5f53\u4e14\u4ec5\u5f53 $gcd(a, b) | c$ $$ax + by = gcd(a, b)$$<\/p>\n $$= gcd(b, a \\bmod {b}) $$<\/p>\n $$=bx\u2032 + (a \\bmod {b})y\u2032$$<\/p>\n $$=bx\u2032 + (a \u2212 \u230a \\frac{a}{b}\u230b \u00d7 b)y\u2032$$<\/p>\n $$=y\u2032 + b(x\u2032 \u2212 \u230a\\frac{a}{b}\u230by\u2032)$$<\/p>\n \u5176\u4e2d $x\u2032$ \u548c $y\u2032$ \u662f\u4e0d\u5b9a\u65b9\u7a0b $bx + (a \\bmod {b})y = gcd(b, a \\bmod {b})$\u7684\u89e3\u3002<\/p>\n \u5982\u679c\u6c42\u51fa\u4e86 $x\u2032$ \u548c $y\u2032$\uff0c\u5c31\u53ef\u4ee5\u6839\u636e\u5bf9\u5e94\u7cfb\u6570\u76f8\u7b49\u7b97\u51fa $x = y\u2032$\uff0c$y = x\u2032 \u2212 \u230a \\frac{a}{b}\u230by\u2032$\u3002<\/p>\n \u5bf9\u4e24\u4e2a\u6574\u6570 $a, b$\uff0c\u5982\u679c\u5b83\u4eec\u9664\u4ee5 $d$ \u7684\u4f59\u6570\u76f8\u540c\uff0c\u5219\u79f0\u5b83\u4eec \u6a21 $d$ \u540c\u4f59\uff0c\u8bb0\u4f5c:<\/p>\n $$a \\equiv b \\enspace(\\bmod{d})$$<\/p>\n \u6b63\u6574\u6570 $p$ \u662f\u8d28\u6570\u7684\u5145\u8981\u6761\u4ef6\u4e3a $(p \u2212 1)! \u2261 \u22121 (\\bmod p)$\u3002<\/p>\n \u5b9a\u4e49\u6b27\u62c9\u51fd\u6570 $\\varphi(n)$ \u8868\u793a\u5c0f\u4e8e $n$ \u7684\u6570\u4e2d\u4e0e $n$ \u4e92\u8d28\u7684\u6570\u7684\u4e2a\u6570\uff1b\u7279\u522b\u7684\uff0c$\\varphi(1) = 1$\u3002<\/p>\n \u79ef\u6027\uff1a\u5982\u679c $gcd(a, b) = 1$\uff0c\u5219 $\\varphi(a \u00d7 b) = \\varphi(a) \u00d7 \\varphi(b)$\u3002<\/p>\n \u6b27\u62c9\u53cd\u6f14\uff1a$\\sum_{d|n} \\varphi(d) = n\u3002$<\/p>\n \u6027\u8d283\uff1a\u5bf9\u4efb\u610f\u5b9e\u6570$p\uff0c\\varphi(p^k) = p^k \u2212 p^{k\u22121}$\u3002<\/p>\n \u5355\u4e2a\u6b27\u62c9\u51fd\u6570<\/strong>\uff1a\u8bbe $n$ \u7684\u552f\u4e00\u5206\u89e3\u5f0f\u662f\uff1a<\/p>\n $$n = p_1^{k_1} p_2^{k_2} \\cdots p_s^{k^s}$$<\/p>\n \u7531\u6027\u8d283\u53ef\u5f97<\/p>\n $$\\varphi (n) = {\\textstyle \\prod_{i=1}^{s}\\varphi(p_i^{k_i})} $$<\/p>\n \u7ebf\u6027\u6b27\u62c9\u51fd\u6570<\/strong>\uff1a\u5728\u7ebf\u6027\u7b5b\u7684\u540c\u65f6\u53ef\u4ee5\u7b5b\u51fa\u6b27\u62c9\u51fd\u6570\uff0c\u8bbe $p$ \u662f $i$ \u7684\u6700\u5c0f\u8d28\u56e0\u5b50\uff0c\u5206\u4e09\u79cd\u60c5\u51b5\u8ba8\u8bba\uff1a<\/p>\n $i$ \u4e3a\u8d28\u6570\uff1a$\\varphi (i) = i \u2212 1$<\/p>\n<\/li>\n $p$ \u662f $\\frac{i}{p}$ \u7684\u8d28\u56e0\u5b50\uff1a$\\varphi (i) = \\varphi(\\frac{i}{p}) \u00d7 p$\u3002<\/p>\n<\/li>\n $p$ \u548c $\\frac{i}{p}$ \u4e92\u8d28\uff1a$\\varphi(i) = \\varphi(\\frac{i}{p})\\varphi(p)$\u3002<\/p>\n<\/li>\n<\/ol>\n\u6211\u771f\u7684\u53d7\u4e0d\u4e86\u4e86\uff01\uff01\uff01\u4e00\u4e2a\u665a\u4e0a\u5c31\u53ea\u5199\u4e86\u8fd9\u4e48\u70b9\u3002\u6570\u8bba\u771f\u2122\u6bd2\u7624QAQ$\\enspace\\enspace\\enspace\\enspace$--20230815<\/span>\n \u5728\u6a21 $p$ \u540c\u4f59\u4e0b\uff0c\u5bf9\u6bcf\u4e2a $x$\uff0c\u80fd\u627e\u5230\u4e00\u4e2a\u6574\u6570 $x^{\u22121} \u2208 [1, p)$\uff0c\u4f7f\u4efb\u4f55\u6570\u9664\u4ee5 $x$ \u7b49\u4ef7\u4e8e\u4e58 $x^{\u22121}$\u3002\u8fd9\u6837\u7684 $x^{\u22121}$ \u79f0\u4e3a $x$ \u5728\u6a21 $p$ \u540c\u4f59\u4e0b\u7684\u9006\u5143\u3002<\/p>\n \u663e\u7136\uff0c\u9006\u5143 $x$ \u5e94\u6ee1\u8db3 $xx^{\u22121} \u2261 1 (\\bmod p)$\u3002<\/p>\n \u4ee5\u5bb9\u6613\u7406\u89e3\u7684\u89d2\u5ea6\u6765\u8bb2\uff1a\u5bf9\u4e8e\u4efb\u610f\u6574\u6570 $x(\\bmod{p})$ \u7684\u9006\u5143\u8868\u793a\u4e3a\uff1a<\/p>\n $$x^{-1}(\\bmod n)$$<\/p>\n \u9006\u5143\u5b58\u5728\u6027\u5b9a\u7406<\/strong>\uff1a$x$ \u5728\u6a21 $p$ \u540c\u4f59\u4e0b\u5b58\u5728\u9006\u5143\u5f53\u4e14\u4ec5\u5f53 $gcd(x, p) = 1$<\/p>\n \u53ef\u901a\u8fc7\u53cd\u8bc1\u6cd5\u8fdb\u884c\u8bc1\u660e\uff0c\u82e5\u9700\u8be6\u7ec6\u6b65\u9aa4\u8bf7\u81ea\u884c\u67e5\u9605\u8d44\u6599\u3002<\/p>\n \u5b9a\u7406<\/strong>\uff1a\u6a21 $p$ \u540c\u4f59\u4e0b\uff0c\u4e00\u4e2a\u6574\u6570 $x$ \u7684\u9006\u5143\u82e5\u5b58\u5728\uff0c\u5219\u552f\u4e00\u3002 \u5b9a\u7406<\/strong>\uff1a\u5728\u6a21\u8d28\u6570 $p$ \u540c\u4f59\u4e0b\uff0c$[1, p \u2212 1]$ \u5185\u6240\u6709\u6574\u6570\u7684\u9006\u5143\u4e92\u4e0d\u76f8\u540c\u3002 \u5b9a\u7406<\/strong>\uff1a\u4e00\u4e2a\u6570\u7684\u9006\u5143\u7684\u9006\u5143\u7b49\u4e8e\u5b83\u81ea\u8eab\u3002 \u5bf9\u4efb\u610f\u7ed9\u5b9a\u7684 $x$ \u548c $p$\uff0c\u663e\u7136 $x \u00d7 x^{\u22121} \u2261 1 \\pmod p$ \u53ef\u4ee5\u5229\u7528\u8fd9\u4e2a\u5f0f\u5b50\u8ba1\u7b97 x^{\u22121}\u3002<\/p>\n \u4e0a\u5f0f\u7b49\u4ef7\u4e8e $xx^{\u22121} = kp + 1 \u21d0\u21d2 xx^{\u22121} + pk = 1$\u3002<\/p>\n \u5176\u4e2d $x$ \u548c $p$ \u662f\u5df2\u77e5\u91cf\uff0c\u6240\u4ee5\u4e0a\u5f0f\u662f\u4e00\u4e2a\u4e0d\u5b9a\u65b9\u7a0b\uff0c$x^{\u22121}$ \u548c $k$\u662f\u53d8\u91cf\u3002\u7528 $exgcd$ \u6c42\u89e3\u53ef\u4ee5\u5f97\u5230 $x^{\u22121}$\u3002<\/p>\n \u6839\u636e\u4e0d\u5b9a\u65b9\u7a0b\u6709\u89e3\u7684\u6761\u4ef6\uff0c$gcd(x, p) | 1 \u21d0\u21d2 gcd(x, p) = 1$\u3002\u8fd9\u548c\u9006\u5143\u5b58\u5728\u6027\u5b9a\u7406\u4e5f\u662f\u76f8\u9002\u5e94\u7684\u3002<\/p>\n \u6b27\u62c9\u5b9a\u7406 (Euler Theorem)<\/strong>\uff1a\u5bf9\u4efb\u610f\u6b63\u6574\u6570 $a$, $m$ \u4e14 $gcd(a, m) = 1$\uff0c\u4e00\u5b9a\u6709\uff1a$a^{\\varphi (m)} \u2261 1 \\pmod m$<\/p>\n \u8bc1\u660e\u81ea\u884c\u67e5\u9605\u8d44\u6599<\/p>\n \u8d39\u9a6c\u5c0f\u5b9a\u7406\uff08Fermat\u2019s Little Theorem\uff09<\/strong>\uff1a\u5bf9\u4efb\u610f\u6574\u6570 $a$ \u548c\u8d28\u6570 $p$\uff0c$a^{p\u22121} \u2261 1 \\pmod p$\u3002<\/p>\n \u8bc1\u660e\u8bf7\u81ea\u884c\u67e5\u9605\u8d44\u6599<\/p>\n \u6839\u636e\u8d39\u9a6c\u5c0f\u5b9a\u7406\uff0c$a^{p\u22121} \u2261 1\\pmod p$\u3002<\/p>\n \u4e24\u4fa7\u540c\u4e58 $a^{\u22121}$\uff0c\u5f97\u5230 $a^{\u22121} \u2261 a^{p\u22122} \\pmod p$\u3002<\/p>\n \u8fd9\u5c31\u5f97\u5230\u4e86\u9006\u5143\u7684\u7b2c\u4e8c\u79cd\u6c42\u6cd5\uff1a\u5feb\u901f\u5e42\u6c42\u51fa $a^{p\u22122}\\pmod p$\u5373\u53ef\u3002<\/p>\n \u8bbe $inv_i$ \u8868\u793a $i$ \u7684\u9006\u5143\uff0c\u6709\u9012\u63a8\u5f0f\uff1a<\/p>\n $ inv_{i} \u2261 \u2212 \u230a\\frac{p}{i} \u230b \u00d7 inv _{p \\mod i} \\pmod p $<\/p>\n \u8fb9\u754c\u4e3a $inv_1 = 1$\u3002<\/p>\n \u6211\u4eec\u7ed9\u5b9a $N$ \u4e2a\u7ebf\u6027\u540c\u4f59\u65b9\u7a0b\u7ec4\uff1a<\/p>\n\u6570\u8bba<\/h1>\n
\u7ebf\u6027\u7b5b<\/h2>\n
bitset<100000> vis;\nvector<int> p;\n\nvoid init() {\n p.push_back(-1);\n for (int i = 2; i <= 100000; i++) {\n if (!vis[i]) p.push_back(i);\n for (int j = 1; j <= p.size() && i * p[j] <= 100000; j++) {\n vis[i * p[j]] = 1;\n if (i % p[j] == 0) break;\n }\n }\n}\n<\/code><\/pre>\n
int n, T, p[maxn \/ 10], Min[maxn]; \/\/Min\u4e2d\u5b58\u7684\u5143\u7d20\u4fbf\u662f\u4e00\u4e2a\u6570\u6700\u5c0f\u7684\u8d28\u56e0\u5b50\nvoid GetPrime() {\n for (int i = 2; i <= maxn; i++) {\n if (!vis[i]) {\n p[++p[0]] = i;\n Min[i] = i;\n }\n for (int j = 1; j <= p[0] && 1ll * i * p[j] < maxn; j++) {\n vis[i * p[j]] = 1;\n Min[i * p[j]] = p[j];\n if (i % p[j] == 0)\n break;\n }\n }\n}<\/code><\/pre>\n
cin >> x;\nwhile(x > 1) x \/= Min[x];<\/code><\/pre>\n
\u7b97\u672f\u57fa\u672c\u5b9a\u7406<\/code>\u3002<\/p>\n
#include <bits\/stdc++.h>\nusing namespace std;\nconst int maxn = 20000000 + 5;\n\nint pri[maxn], phi[maxn], mi[maxn], mu[maxn];\nbitset<maxn> vis;\n\nvoid init(){\n mu[1] = 1;\n for(int i = 2; i <= maxn - 5; i++) {\n if(!vis[i]) pri[++pri[0]] = i, mi[i] = i, phi[i] = i - 1, mu[i] = -1;\n for(int j = 1; j <= pri[0] && i * pri[j] <= maxn - 5; j++) {\n int tt = i * pri[j];\n vis[tt] = 1;\n mi[tt] = pri[j];\n if(i % pri[j] == 0) {\n phi[tt] = phi[i] * pri[j];\n break;\n }\n else phi[tt] = phi[i] * phi[pri[j]];\n mu[tt] = -mu[i];\n }\n }\n}\n\nint main() {\n freopen("a.out", "w", stdout);\n ios::sync_with_stdio(0);\n cin.tie(0);\n cout.tie(0);\n init();\n printf("%d\\n", mu[6]);\n\n return 0; \n} \n<\/code><\/pre>\n
\u552f\u4e00\u5206\u89e3\u5b9a\u7406<\/h2>\n
\u552f\u4e00\u5206\u89e3\u5b9a\u7406\u4e0e LCM\u3001GCD \u4e4b\u95f4\u7684\u5173\u7cfb<\/h3>\n
\u56e0\u5b50<\/h2>\n
\u56e0\u5b50\u548c<\/h3>\n
\n\u5176\u4e2d $p$ \u662f\u8d28\u6570\uff0c$k$ \u662f\u4e00\u4e2a\u975e\u8d1f\u6574\u6570\uff0c$m$ \u8868\u793a\u8be5\u6570\u6700\u5c11\u53ef\u4ee5\u88ab\u51e0\u4e2a\u7d20\u6570\u8868\u793a\uff0c\u8bd5\u6c42\uff1a<\/p>\n\u4ee3\u7801\u5b9e\u73b0<\/h3>\n
\n
\n
\u53c2\u8003\u4ee3\u7801<\/h4>\n
void sol() {\n for(int i = 2; i <= n; i++) {\n if(!vis[i]) p[++p[0]] = i, f[i] = g[i] = 1 + i;\/\/\u60c5\u51b5\u4e00\n for(int j = 1, t; (t = i * p[j]) <= n && j <= p[0]; j++) {\n vis[t] = 1;\n if(i % p[j]) g[t] = p[j] + 1, f[t] = f[i] * g[t]; \/\/\u60c5\u51b5\u4e8c\n else { \/\/\u60c5\u51b5\u4e09\n g[t] = g[i] * p[j] + 1;\n f[t] = f[i] \/ g[i] * g[t];\n break;\n }\n }\n }\n}<\/code><\/pre>\n
\u4e0d\u5b9a\u65b9\u7a0b<\/h2>\n
\u5b9a\u4e49<\/h3>\n
\u6c42\u89e3<\/h3>\n
\n\u5148\u8003\u8651\u5982\u4f55\u6c42 $ax + by = gcd(a, b)$<\/p>\n\u540c\u4f59<\/h2>\n
\u5a01\u5c14\u900a\u5b9a\u7406<\/h2>\n
\u6b27\u62c9\u51fd\u6570<\/h2>\n
\u5b9a\u4e49<\/h3>\n
\u6027\u8d28<\/h3>\n
\u8ba1\u7b97<\/h3>\n
\n
\u9006\u5143<\/h2>\n
\u5b9a\u4e49<\/h3>\n
\u6027\u8d28<\/h3>\n
\n\u8bc1\u660e<\/strong>\uff1a\u8003\u8651\u53cd\u8bc1\u6cd5\uff1b\u5047\u8bbe $x$ \u6709\u4e24\u4e2a\u4e0d\u540c\u7684\u9006\u5143 $i_1\uff0ci_2$\uff0c\u6ee1\u8db3 $xi_1 \\equiv 1 \\pmod{p} $\uff0c$xi_2 \\equiv 1 \\pmod{p} $\u3002\u6839\u636e\u540c
\n\u4f59\u7684\u4f20\u9012\u6027\uff0c$xi_1 \\equiv xi_2 \\pmod{p} $\u5728\u540c\u4f59\u53f7\u4e24\u4fa7\u5de6\u4e58 $i_1$\uff0c\u5f97\u5230\uff1a$(i_1x)i_1 \u2261 (i_1x)i_2\\pmod p \u21d0\u21d2 1i_1 \u2261 1i_2 \\pmod p$<\/p>\n
\n\u8bc1\u660e<\/strong>\uff1a\u53cd\u8bc1\uff0c\u5047\u8bbe $x$, $y$ \u7684\u9006\u5143\u5747\u4e3a $i$\uff0c\u5219 $x_i \u2261 y_i \\pmod p$\u3002\u4e24\u4fa7\u540c\u4e58 $i^{\u22121}$ \u7acb\u5f97 $x \u2261 y \\pmod p$\uff0c\u77db\u76fe\u3002<\/p>\n
\n\u8bc1\u660e<\/strong>\uff1a\u7531\u6a21\u610f\u4e49\u4e0b\u4e58\u6cd5\u4ea4\u6362\u5f8b\u548c\u7ed3\u5408\u5f8b\u7acb\u5f97\u3002<\/p>\n\u901a\u8fc7\u6269\u5c55\u6b27\u51e0\u91cc\u5f97(exgcd) \u8ba1\u7b97\u9006\u5143<\/h3>\n
\u6b27\u62c9\u5b9a\u7406<\/h3>\n
\u8d39\u9a6c\u5c0f\u5b9a\u7406<\/h3>\n
\u901a\u8fc7\u8d39\u9a6c\u5c0f\u5b9a\u7406\u6c42\u9006\u5143<\/h4>\n
\u4e2d\u56fd\u5269\u4f59\u5b9a\u7406<\/h2>\n
\u4e2d\u56fd\u5269\u4f59\u5b9a\u7406\u95ee\u9898<\/h3>\n