{"id":911,"date":"2023-11-15T20:28:03","date_gmt":"2023-11-15T12:28:03","guid":{"rendered":"http:\/\/ggapa.net:81\/?p=911"},"modified":"2023-11-17T11:42:32","modified_gmt":"2023-11-17T03:42:32","slug":"noip2023-%e6%a8%a1%e6%8b%9f%e8%b5%9b2023-11-14","status":"publish","type":"post","link":"http:\/\/ggapa.net:81\/2023\/11\/15\/noip2023-%e6%a8%a1%e6%8b%9f%e8%b5%9b2023-11-14\/","title":{"rendered":"NOIP2023 \u6a21\u62df\u8d5b(2023.11.14)"},"content":{"rendered":"
${\\color{Red} \\mathrm{\u5199\u7684\u5f88\u5783\u573e\uff0c\u5f85\u8865\u5145} } $
\nUpdate on 2023.11.17 \u4fee\u6539\u7b14\u8bef\uff0c\u8865\u5145\u5185\u5bb9\u3002<\/p>\n
\u6c42 $m!$ \u5728\u6a21 $p$ \u4e0b\u7684\u503c\uff0c\u4fdd\u8bc1 $p$ \u662f\u7d20\u6570\u3002<\/p>\n \u8003\u70b9\uff1a\u5a01\u5c14\u900a\u5b9a\u7406\u3002<\/p>\n \u7531\u5a01\u5c14\u900a\u5b9a\u7406\u53ef\u77e5\uff0c\u82e5 $p$ \u4e3a\u7d20\u6570\uff0c\u5219\u6709$(p-1)! \\equiv p-1\\pmod{p}$\u3002<\/p>\n \u53ef\u901a\u8fc7\u4ee5\u4e0a\u5b9a\u7406\u5f97 $(p-1)! \\pmod{p}$ \u7684\u503c\u3002<\/p>\n \u82e5 $m \\ge p$\uff0c\u7ed3\u679c\u4e3a $0$\u3002<\/p>\n \u82e5 $m < p$\uff0c\u9898\u76ee\u4e2d\u8ba9\u6211\u4eec\u6c42\u7684\u662f\uff1a<\/p>\n $$\\prod_{1}^{m} \\pmod{p}$$<\/p>\n \u4f46\u6211\u4eec\u5df2\u77e5\uff1a<\/p>\n $$\\prod_{1}^{p - 1} \\pmod{p}$$<\/p>\n \u6240\u4ee5\u5c31\u9700\u8981\u4e58\u4e0a\u4ee5\u4e0b\u5f0f\u5b50\uff0c\u6765\u5220\u53bb\u591a\u4f59\u7684\u90e8\u5206\u3002<\/p>\n $$\\prod_{i=m+1}^{p-1} i^{-1} \\pmod{p}$$<\/p>\n \u6700\u7ec8\u7684\u7b54\u6848\u4e3a\uff1a<\/p>\n $$(p-1) \\times \\prod_{i=m+1}^{p-1} i^{-1} \\pmod{p}$$<\/p>\n \u6c42\u9006\u5143\u53ef\u901a\u8fc7\u8d39\u9a6c\u5c0f\u5b9a\u7406\u5b9e\u73b0\u3002<\/p>\n \u8003\u70b9\uff1a\u5206\u5757<\/p>\n \u8fd9\u9053\u9898\u7684 \u505a\u6cd5\u5f88\u591a\u3002<\/p>\n \u8003\u8651\u5efa\u7acb\u53cd\u56fe\uff0c\u7528\u7ebf\u6bb5\u6811\u4f18\u5316\u3002<\/p>\n \u5bf9\u4e8e\u6bcf\u4e00\u4e2a\u70b9\u6784\u5efa\u5168\u5c40\u7ebf\u6bb5\u6811\uff0c\u5728\u8fde\u8fb9\u7684\u65f6\u5019\u7531\u66f4\u5927\u7684\u8282\u70b9\u5411\u66f4\u5c0f\u7684\u8282\u70b9\u8fde\u8fb9\u3002\u4f46\u6bcf\u4e2a\u70b9\u8fde\u51fa\u7684\u8fb9\u662f $O(\\log n)$ \u7684\uff0c\u518d\u8dd1\u4e00\u904d\u6700\u77ed\u8def\uff0c\u6574\u4f53\u65f6\u95f4\u590d\u6742\u5ea6\u53d8\u4e3a $O(n \\log^2 n)$ \u4e0d\u80fd\u901a\u8fc7\u8fd9\u9053\u9898\u76ee\u3002<\/p>\n \u56e0\u4e3a\u6bcf\u6761\u8fb9\u7684\u8fb9\u6743\u53ef\u4ee5\u5b9a\u4e3a $1$ \uff0c\u6bcf\u4e2a\u70b9\u5728\u7b2c\u4e00\u6b21\u8fbe\u5230\u65f6\u76f4\u63a5\u6254\u8fdb\u961f\u5217\u91cc\uff0c\u6545\u53ef\u4e0d\u7528\u4f18\u5148\u961f\u5217\u5b8c\u6210\u8fd9\u9053\u9898\u3002\u65f6\u95f4\u590d\u6742\u5ea6 $O(n\\log n)$\uff0c\u7406\u8bba\u4e0a\u4e0d\u80fd\u901a\u8fc7\u6b64\u9898\u3002\u5199\u7684\u4f18\u79c0\u53ef\u4ee5\u5f97 86pts\u3002<\/p>\n \u53d1\u73b0\u4e0d\u80fd\u518d\u901a\u8fc7\u7ebf\u6bb5\u6811\u8fdb\u884c\u4f18\u5316\uff0c\u8003\u8651\u5728\u6784\u5efa\u8fd4\u56fe\u65f6\u4e0d\u8fde\u90a3\u4e48\u591a\u8fb9\u6765\u4f18\u5316\u7a0b\u5e8f\u3002\u53d1\u73b0 $(n-L+R) \\times d^{-1}$ \u5c31\u53ef\u4ee5\u5f97\u5230\u6211\u4eec\u6240\u9700\u8981\u7684\u70b9\u3002\u4f8b\u5982 : <\/p>\n \u8003\u70b9\uff1a \u6574\u4f53\u4e8c\u5206<\/p>\n \u83ab\u961f\u90e8\u5206\u5206\uff0c\u80cc\u5305\u5408\u5e76\u90e8\u5206\u5206<\/p>\n \u9700\u8981\u8fdb\u884c\u79bb\u7ebf\u64cd\u4f5c\uff0c\u5e76\u4e14\u628a\u6bcf\u4e00\u79cd\u8be2\u95ee\u90fd\u626f\u4e0a\u5173\u7cfb\uff0c\u80cc\u5305\u5408\u5e76\u4e0d\u884c\u3002<\/p>\n \u8003\u8651\u6574\u4f53\u4e8c\u5206\u548c\u5206\u6cbb\u3002<\/p>\n \u5bf9\u4e8e\u6bcf\u4e00\u4e2a\u80cc\u5305\u505a\u524d\u7f00\u6700\u5927\u503c\u5904\u7406\uff0c\u540e\u7f00\u4e5f\u5904\u7406\u4e86\uff0c\u53ef\u4ee5 $O(m)$ \u67e5\u8be2\uff0c\u540e\u4f7f\u7528\u6574\u4f53\u4e8c\u5206\u3002<\/p>\n\u9898\u76ee\u5927\u610f<\/h5>\n
\u5206\u6790\u4e0e\u89e3\u7b54<\/h5>\n
#include <bits\/stdc++.h>\nusing namespace std;\nlong long qpow(long long a, long long b, long long p) {\n long long ans = 1;\n while (b) {\n if (b & 1)\n ans = ans * a % p;\n a = a * a % p;\n b >>= 1;\n }\n return ans;\n}\nint main() {\n freopen("factorial.in", "r", stdin);\n freopen("factorial.out", "w", stdout);\n cin.tie(0)->sync_with_stdio(0);\n int T;\n cin >> T;\n while (T--) {\n long long m, p;\n cin >> m >> p;\n if (m >= p)\n cout << 0 << '\\n';\n else {\n long long ans = p - 1;\n for (long long i = p - 1; i > m; i--) ans = 1ll * ans * qpow(i, p - 2, p) % p;\n cout << ans << '\\n';\n }\n }\n return 0;\n}<\/code><\/pre>\n
T2<\/a><\/h1>\n
\u9898\u76ee\u5927\u610f<\/h5>\n
\u5206\u6790\u4e0e\u89e3\u7b54<\/h5>\n
\n$$n = 10,d = 4, \\gcd(n, d) = 2\uff0cL=1,R=3$$
\n\u6ca1\u6709\u5fc5\u8981\u4e00\u6b21\u6027\u628a\u56fe\u5168\u90e8\u6784\u5efa\u51fa\u6765\uff0c\u56e0\u4e3a\u6784\u5efa\u51fa\u6765\u5c31\u5df2\u7ecf\u7206\u4e86\u3002<\/p>\nT3<\/a><\/h1>\n
\u5206\u6790\u4e0e\u89e3\u7b54<\/h5>\n
T4<\/a><\/h1>\n