POJ 1845 Sumdiv

Sumdiv
Time Limit: 1000MS Memory Limit: 30000K
Total Submissions: 10953 Accepted: 2592

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

 个人感觉这题是很棒的,要熟悉性质,还要会用递归的方法求等比数列,http://blog.csdn.net/lyy289065406/article/details/6648539 参照她的博客学习吧
#include <stdio.h>
#include <string.h>
#include <math.h>
__int64 xiang[100000],xishu[100000];
__int64 mod=9901;
int main()
{
    __int64 deal(__int64 p,__int64 n);
    __int64 i,j,n,m,s,t,top,res,key;
    while(scanf("%I64d %I64d",&n,&m)!=EOF)
    {
        if(n==0)
        {
            printf("0\n");
            continue;
        }
        memset(xiang,0,sizeof(xiang));
        memset(xishu,0,sizeof(xishu));
        for(i=2,top=0;i<=(int)(sqrt((double)(n))+0.01);)
        {
            if(n%i==0)
            {
                while(n%i==0)
                {
                    xiang[top]=i; xishu[top]++;
                    n=n/i;
                }
            }
            top++;
            if(i==2)
            {
                i=3;
            }else
            {
                i+=2;
            }
        }
        if(n!=1)
        {
            xiang[top]=n;
            xishu[top]++;
            top++;
        }
        for(i=0,res=1;i<=top-1;i++)
        {
            t=deal(xiang[i],xishu[i]*m);
            res=(res*t)%mod;
        }
        printf("%I64d\n",res);
    }
    return 0;
}
__int64 f(__int64 p,__int64 n)
{
    __int64 res=1;
    p=p%mod;
    while(n>1)
    {
        if(n&1)
        {
            res=(res*p)%mod;
        }
        p=(p*p)%mod;
        n=n/2;
    }
    return ((res*p)%mod);
}
__int64 deal(__int64 p,__int64 n)
{
    __int64 t;
    if(n==0)
    {
        return 1;
    }
    if(n%2)
    {
        t=deal(p,n/2);
        return (((1+f(p,n/2+1))%mod)*(t%mod))%mod;
    }else
    {
        t=deal(p,n/2-1);
        return ((((1+f(p,n/2+1))%mod)*(t%mod))%mod+f(p,n/2)%mod)%mod;
    }
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值