题目大意:给定a和b,1 <= a, b <= 1000000,求出a ^ b的因子个数,暂且称为n,计算1^3+2^3+......n^3。
分析:立方和公式:1^3+2^3+......n^3 = (n * (n+1) / 2) ^ 2。利用唯一分解定理求出a ^ b的因子个数,但是数据范围实在是太大,光因子个数就会爆long long,所以,在每次求出prime[ i ]的指数时,就要进行一次运算。
#include<iostream>
#include<cstdio>
#include<string.h>
#include<cmath>
using namespace std;
typedef long long ll;
const int N=1100;
ll mod=10007;
ll a,b;
bool p[N];
int prime[N],cnt=0;
void isprime()
{
memset(p,0,sizeof p);
p[0]=p[1]=1;
for(int i=2;i<N;i++)
{
if(!p[i]) prime[cnt++]=i;
for(int j=0;j<cnt&&(ll)i*prime[j]<N;j++)
{
p[i*prime[j]]=1;
if(i%prime[j]==0) break;
}
}
}
int main()
{
int cas=1;
isprime();
while(~scanf("%lld%lld",&a,&b))
{
ll res,ans=1;
for(int i=0;i<cnt;i++)
{
if(a==1) break;
res=0;
while(a%prime[i]==0)
{
res++;
a/=prime[i];
}
res=(res*b+1)*(res*b+2)/2%mod;//每次求出指数时就进行一次运算
ans=ans*res%mod*res%mod;
}
if(a!=1)
{
res=1;
res=(res*b+1)*(res*b+2)/2%mod;
ans=ans*res%mod*res%mod;
}
printf("Case %d: %lld\n",cas++,ans);
}
return 0;
}