Description
Consider two natural numbers A and B. Let S be the sum of all natural divisors of A^B. Determine S modulo 9901 (the rest of the division of S by 9901).
Input
The only line contains the two natural numbers A and B, (0 <= A,B <= 50000000)separated by blanks.
Output
The only line of the output will contain S modulo 9901.
Sample Input
2 3
Sample Output
15
Hint
2^3 = 8.
The natural divisors of 8 are: 1,2,4,8. Their sum is 15.
15 modulo 9901 is 15 (that should be output).
The natural divisors of 8 are: 1,2,4,8. Their sum is 15.
15 modulo 9901 is 15 (that should be output).
题意:求 a^b 的所有约数的和
题解:
tips:
#include<iostream> #include<algorithm> #include<cstdio> #include<cmath> #include<cstring> using namespace std; const int mod=9901; const int maxn=5e5+5; typedef long long ll; ll p[maxn]; int prime[maxn]; void is_prime() { int cnt=0,i,j; memset(prime,0,sizeof(prime)); for(i=2; i<maxn; i++) { if(prime[i]==0) { p[++cnt]=i; for(j=2*i; j<maxn; j=j+i) { prime[j]=1; } } } } ll multi(ll A,ll n,ll k) { ll b=0; while(n>0) { if(n&1) { b=(b+A)%k; } n=n>>1; A=(A+A)%k; } return b; } ll getresult(ll A,ll n,ll k) { ll b=1; while(n>0) { if(n&1) { b=multi(b,A,k); } n=n>>1; A=multi(A,A,k); } return b; } void solve(ll A,ll B) { int i; ll ans=1; for(i=1; p[i]*p[i]<=A; i++) { if(A%p[i]==0) { int num=0; while(A%p[i]==0) { num++; A=A/p[i]; } ll m=(p[i]-1)*9901; ans*=(getresult(p[i],num*B+1,m)+m-1)/(p[i]-1); ans%=9901; } } if(A>1) { ll m=9901*(A-1); ans *= (getresult(A,B+1,m)+m-1)/(A-1); ans%=9901; } cout<<ans<<endl; } int main() { ll A,B; is_prime(); while(cin>>A>>B) { solve(A,B); } return 0; }