Sumdiv

Sumdiv
Time Limit: 1000MS Memory Limit: 30000K
Total Submissions: 24296 Accepted: 6022
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).
Source

Romania OI 2002


题意:求AB的所有约数之和,并对其取模9901再输出。
题意很简单。思路:
1)整数唯一分解定理
2)约数求和
3)快速幂

#include<algorithm>
#include<stdio.h>
#include<iostream>
#include<string>
#include<string.h>
using namespace std;
typedef long long int ll;
const int MOD=9901;
const int N=10000+10;
int p[N],n[N];
ll power(ll p,ll n)
{
    ll sq=1;
    while(n)
    {
        if(n&1)
          sq=(sq*p)%MOD;
        n>>=1;
        p=(p*p)%MOD;
    }
    return sq;
}
ll sum(ll p,ll n)
{
    if(n==0)
        return 1;
    if(n%2==0)
    return (sum(p,n/2-1)*(1+power(p,n/2+1))+power(p,n/2))%MOD;
    else
    return (sum(p,n/2)*(1+power(p,n/2+1)))%MOD;
}
int main()
{
    int a,b;
    while(~scanf("%d%d",&a,&b))
    {
        int k=0;
        for(int i=2;i*i<=a;)
        {
            if(a%i==0)
            {
                p[++k]=i;
                n[k]=0;
                while(!(a%i))
                {
                    n[k]++;
                    a/=i;
                }
            }
            if(i==2)
            i++;
            else
            i+=2;
        }
        if(a!=1)
        {
            p[++k]=a;
            n[k]=1;
        }
        int ans=1;
        for(int i=1;i<=k;i++)
        {
            ans=(ans*sum(p[i],n[i]*b)%MOD)%MOD;
        }
        printf("%d\n",ans);
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值