POJ1845又是sigemapi转化成pisigema的形式,证明过程见我的HDU2421

Sumdiv
Time Limit: 1000MS Memory Limit: 30000K
Total Submissions: 13761 Accepted: 3389

Description

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^B的因子和

思路:将A质因子分解成(p1^k1*p2^k2*...pn^kn)*B的形式,若设A^B的因子ti=(p1^ti1*p2^ti2...*pi^tin)的形式,则对他们进行求和实际上等价于求(1+p1^1+p1^2...+p1^bk)*(1+p2^1+p2^2+..p2^n)*...(1+pn^1+pn^2+....pn^n)的形式,接着对每一个等比形式的∑进行二分求解,在过程中取模就可以了。


#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;

long long A,B;
long long a[10005];
long long n[10005];
const long long mod=9901;
long long power(long long a,long long b)
{
    long long res=1;
    while(b)
    {
        if(b&1)
            res=(res*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}
long long sum(long long a,long long b)
{
    if(b==0)
        return 1;
    if(b%2==1)
        return (sum(a,b/2)*(power(a,b/2+1)+1))%mod;
    else
        return (sum(a,b-1)+power(a,b))%mod;

}
int main()
{
    while(cin>>A>>B)
    {
        long long cnt=0;
        for(int i=2;i*i<=A;i++)
        {
            if(A%i==0)
            {
                a[cnt]=i;
                n[cnt]=0;
                while(A%i==0)
                {
                    A/=i;
                    n[cnt]++;
                }
                cnt++;
            }
        }
        if(A!=1)
        {
            a[cnt]=A;
            n[cnt++]=1;
        }
        long long ans=1;
        for(long long  i=0;i<cnt;i++)
        {
            ans=(ans*sum(a[i],B*n[i]))%mod;
            ans%=mod;
        }
        cout<<ans<<endl;
    }
    return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值