蒟蒻求助数学题
  • 板块P1593 因子和
  • 楼主Jorisy
  • 当前回复9
  • 已保存回复9
  • 发布时间2022/4/10 16:55
  • 上次更新2023/10/28 04:04:01
查看原帖
蒟蒻求助数学题
400269
Jorisy楼主2022/4/10 16:55

40pts,WA on #1~10

按算法竞赛进阶指南的分治思路去做的。。。

code:

#include<bits/stdc++.h>
#define ll long long
#define mod 9901
using namespace std;

ll qpow(ll x,ll p)
{
	ll ans=1;
	while(p)
	{
		if(p&1) ans=ans*x%mod;
		else x=x*x%mod;
		p>>=1;
	}
	return ans;
}

ll sum(ll p,ll c)
{
	if(c==0) return 1;
	if(c==1) return p+1;
	if(c&1) return (1+qpow(p,(c+1)/2))*sum(p,(c-1)/2)%mod;
	return ((1+qpow(p,c/2))*sum(p,c/2-1)+qpow(p,c))%mod;
}

int main()
{
	ll a,b,ans=1,i=2,x=0;
	cin>>a>>b;
	while(a>1)
	{
		if(a%i==0)
		{
			x++;
			a/=i;
		}
		else
		{
			ans=ans*sum(i,b*x)%mod;
			i++;
			x=0;
		}
	}
	ans=ans*sum(i,b*x)%mod;
	i++;
	x=0;
	cout<<ans;
 	return 0;
}
2022/4/10 16:55
加载中...