Deciphering Password--唯一分解定理

题目大意:给定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;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值