题意:http://www.lightoj.com/volume_showproblem.php?problem=1054
给你n和m 求n的m次方的所有因子和
和求因子个数有一定的关系,一个数 n 可以表示成 n = p1^a1 * p2^a2 * p3^a3 * ... pk^ak,(其中pi是n的素因子)
那么n的因子和就是 (p1^0+p1^1+p1^2+...+p1^a1)*(p2^0+p2^1+p2^2+...+p2^a2)*...*(pk^0+pk^1+...+pk^ak);
主要是分解质因子,然后可以推出,所有因子的和 等于 (2^0 + 2^1 +2^2 + …… 2^p1)*(3^0 + 3^1 + 3^2 +…… 3^p2) * (5^0 + 5^1 + 5^2 + 5^3 + …… +5^p3)*…………
即所有质因子前p项和的乘积。最后还要注意等比数列 1 + x + x^2 + ...+ x^t的求法,利用递推。
等比数列公式 s=a1(1-q^n)/(1-q);
a/b%p == a*b^(p-2)%p;(当p是素数)
#include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #include<queue> #include<map> #include<math.h> #include<string> #include<vector> using namespace std; #define INF 0x3f3f3f3f #define LL long long #define N 100006 LL mod=1000000007; int a[N],q[N],ans=0; void prime() { for(int i=2;i<N;i++) { if(!a[i]) { q[ans++]=i; for(int j=i;j<N;j+=i) a[j]=1; } } } LL poww(LL a,LL b) { LL c=1; while(b) { if(b&1) c=c*a%mod; b=b/2; a=a*a%mod; } return c; } LL dengbi(LL n,LL k) { if(k==0) return 1;///注意取模 很容易错 加上mod早取模 return ((poww(n,k+1)-1)%mod*poww(n-1,mod-2)%mod+mod)%mod; } int main() { int T,t=1; prime(); scanf("%d",&T); while(T--) { LL n,m,sum=1; scanf("%lld%lld",&n,&m); for(int i=0;i<ans&&q[i]<=(int)sqrt(n);i++) { if(n%q[i]==0)///分解质因子 以及个数 { LL s=0; while(n%q[i]==0) { s++; n=n/q[i]; } sum=sum*dengbi(q[i],s*m)%mod; } } if(n!=1) sum=sum*dengbi(n,m)%mod; printf("Case %d: %lld\n",t++,sum); } return 0; }