2016夏季练习——数论

来源:POJ1845

就是一个计数,中间使用了二分,很机智的做法

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;//竟然是有求p^1+p^2+...+p^n的模板,JZ
typedef long long LL;
const int MAXN = 10010;
const int MOD = 9901;
LL quick_pow(LL a,LL n){
	LL res=1;
	LL temp=a%MOD;
	while(n){
		if(n&1) res=(res*temp)%MOD;
		temp=temp*temp%MOD;
		n>>=1;
	}
	return res;
}
LL sum(LL p,LL n){
	if(p==0) return 0;
	if(n==0) return 1;
	if(n&1){
		return ((1+quick_pow(p,n/2+1))%MOD*sum(p,n/2)%MOD)%MOD;
	}
	else{
		return ((1+quick_pow(p,n/2+1))%MOD*sum(p,n/2-1)+quick_pow(p,n/2)%MOD)%MOD;
	}
}
LL p[MAXN],n[MAXN];
int main(){
	LL a,b;
	while(scanf("%lld%lld",&a,&b)!=EOF){
		int k=0;
		for(int i=2;i<=a/i;){
			if(a%i==0){
				p[k]=i;
				n[k]=0;
				while(!(a%i)){
					n[k]++;
					a/=i;
				}
				k++;
			}
			if(i==2){
				i++;
			}
			else 
				i+=2;
		}
		if(a!=1){
			p[k]=a;
			n[k++]=1;
		}
		LL ans=1;
		for(int i=0;i<k;i++)
		{
			ans=(ans*(sum(p[i],n[i]*b)%MOD))%MOD;
		}
		cout<<ans<<endl;
	}
	return 0;
}

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值