{"id":139,"date":"2011-08-21T23:41:43","date_gmt":"2011-08-21T15:41:43","guid":{"rendered":"http:\/\/wangkaixuan.tech\/?p=139"},"modified":"2020-06-03T23:42:18","modified_gmt":"2020-06-03T15:42:18","slug":"hdu-3123-gcc","status":"publish","type":"post","link":"http:\/\/www.wangkaixuan.tech\/?p=139","title":{"rendered":"hdu 3123 GCC"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>\/*\n\u4e00\u4e2a\u5c0f\u6280\u5de7\u662f\u5f53n>=m\u65f6n!%m==0\n\u6240\u4ee5\u5f53n>=m\u65f6\u76f4\u63a5\u4ee4n==m\u5373\u53ef\n\u8fd9\u6837\u5c31\u4e0d\u7528\u7528\u5904\u7406\u5927\u6570\u4e58\u6cd5\u7684\u65b9\u5f0f\u5904\u7406n!\u4e86 \n*\/\n#define LOCAL\n#include&lt;iostream>\n#include&lt;cstdio>\n#include&lt;cmath>\n#include&lt;cstring>\n#include&lt;cstdlib>\n#include&lt;iomanip>\n#include&lt;string>\n#include&lt;algorithm>\n#include&lt;ctime>\n#include&lt;stack>\n#include&lt;queue>\n#include&lt;vector>\n#define N 10005\nusing namespace std;\nint main()\n{\n#ifdef LOCAL\n       freopen(\"input.txt\",\"r\",stdin);\n       freopen(\"output.txt\",\"w\",stdout);\n#endif\n \n     long long t=1,ans,i,ncase,m,n,nlen,mlen;string str;\n     cin>>ncase;\n     while(ncase--)\n     {\n            \/\/\u6570\u636e\u5904\u7406 \n            cin>>str>>m;\n            nlen=str.size();\n            t=m;mlen=0;\n            while(t){t=t\/10;mlen++;}\n            t=1;n=0;\n            for(i=nlen-1;(i>=0&amp;&amp;i>=nlen-8);i--)\n            {\n                   n+=(str&#91;i]-'0')*t;\n                   t*=10;                \n            }\n            if(nlen>mlen||n>m) {n=m;n--;}\n            \/\/\u8ba1\u7b97 \n            ans=1;t=1;\n            for(i=1;i&lt;=n;i++)\n            {\n                   t=(t*i)%m;\/\/\u9632\u6b62\u6570\u636e\u6ea2\u51fa \n                   ans=(ans+t)%m;            \n            }\n            ans%=m;\/\/\u9632\u6b62\u51fa\u73b0m==1\u51fa\u73b0\u65f6n%m==1\u7684\u60c5\u51b5 \n            cout&lt;&lt;ans&lt;&lt;endl;\n     } \n     return 0;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-139","post","type-post","status-publish","format-standard","hentry","category-06-01-acm"],"_links":{"self":[{"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=\/wp\/v2\/posts\/139","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=139"}],"version-history":[{"count":0,"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=\/wp\/v2\/posts\/139\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=139"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=139"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.wangkaixuan.tech\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=139"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}