您的位置:首页 > 其它

POJ 1845 Sumdiv

2017-12-30 19:58 211 查看
escription

Consider two natural numbers A and B. Let S be the sum of all natural divisors of A^B. Determine S modulo 9901 (the rest of the division of S by 9901).
Input

The only line contains the two natural numbers A and B, (0 <= A,B <= 50000000)separated by blanks.
Output

The only line of the output will contain S modulo 9901.
Sample Input

2 3

Sample Output

15

Hint

2^3 = 8.
The natural divisors of 8 are: 1,2,4,8. Their sum is 15.

15 modulo 9901 is 15 (that should be output).

A=p1^c1*p2^c2*p2^c3

所有因数和=(1+p1^1+....p1^c1)*(1+p2^1+....p2^c2)*(1+p3^1+...p3^c3)

等比数列求和

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long lol;
lol Mod=9901,A,B,lim,ans;
lol pri[10001],cnt[10001],tot;
lol qpow(lol x,lol y)
{
lol res=1;
while (y)
{
if (y&1) res=(res*x)%Mod;
x=(x*x)%Mod;
y/=2;
}
return res;
}
lol get_sum(lol x,lol y)
{
if (y==0) return 1;
if (y%2)
return ((qpow(x,y/2+1)+1)*get_sum(x,y/2))%Mod;
else
return ((qpow(x,y/2+1)+1)*get_sum(x,y/2-1)+qpow(x,y/2))%Mod;
}
int main()
{lol i,s;
cin>>A>>B;
lim=sqrt(A);
for (i=2;i<=lim;i++)
if (A%i==0)
{
s=0;
while (A%i==0)
{
s++;
A/=i;
}
pri[++tot]=i;
cnt[tot]=s*B;
}
if (A!=1)
{
pri[++tot]=A;
cnt[tot]=B;
}
ans=1;
for (i=1;i<=tot;i++)
{
ans=(ans*get_sum(pri[i],cnt[i]))%Mod;
}
cout<<ans;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: