标签:
2 4
12
1 #include <iostream> 2 using namespace std; 3 typedef long long LL; 4 const int maxn = 50; 5 LL p[maxn],n,m,ret,tot; 6 LL quickPow(LL base,LL index){ 7 LL ret = 1; 8 while(index){ 9 if(index&1) ret *= base; 10 index >>= 1; 11 base *= base; 12 } 13 return ret; 14 } 15 void init(LL x){ 16 tot = 0; 17 for(int i = 2; i*i <= x; ++i){ 18 if(x%i == 0){ 19 p[tot++] = i; 20 while(x%i == 0) x /= i; 21 } 22 } 23 if(x > 1) p[tot++] = x; 24 } 25 int main(){ 26 ios::sync_with_stdio(false); 27 while(cin>>n>>m){ 28 init(m); 29 for(int i = 1; i < (1<<tot); ++i){ 30 int cnt = 0; 31 LL tmp = 1; 32 for(int j = 0; j < tot; ++j){ 33 if((i>>j)&1){ 34 cnt++; 35 tmp *= p[j]; 36 } 37 } 38 if(cnt&1) ret += quickPow(m/tmp,n); 39 else ret -= quickPow(m/tmp,n); 40 } 41 cout<<(quickPow(m,n) - ret)<<endl; 42 } 43 return 0; 44 }
标签:
原文地址:http://www.cnblogs.com/crackpotisback/p/4850708.html