标签:size ref pst family exgcd ret 分解 小技巧 namespace
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 23172 | Accepted: 5769 |
Description
Input
Output
Sample Input
2 3
Sample Output
15
Hint
Source
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <cmath> using namespace std; const int mod = 9901; long long cnt[100010],wh[100010],tot,ans = 1; int a,b; void exgcd(long long a,long long b,long long &x,long long &y) { if (!b) { x = 1; y = 0; return; } exgcd(b,a % b,x,y); long long t = x; x = y; y = t - (a / b) * y; return; } long long qpow(long long a,long long b) { long long ans = 1; while (b) { if (b & 1) ans = (ans * a) % mod; a = (a * a) % mod; b >>= 1; } return ans; } int main() { scanf("%d%d",&a,&b); for (int i = 2; i <= sqrt(a); i++) { if (a % i == 0) { wh[++tot] = i; while (a % i == 0) { a /= i; cnt[i]++; } } } if (a) { wh[++tot] = a; cnt[a]++; } for (int i = 1; i <= tot; i++) { long long x,y; exgcd(wh[i] - 1,mod,x,y); ans = (ans * (( qpow(wh[i],cnt[wh[i]] * b + 1) - 1)* x) % mod) % mod; } printf("%lld\n",ans); return 0; }
标签:size ref pst family exgcd ret 分解 小技巧 namespace
原文地址:http://www.cnblogs.com/zbtrs/p/7498446.html