POJ 1845Sumdiv(数论)

Sumdiv

Time Limit: 1000MS Memory Limit: 30000K
Total Submissions: 20041 Accepted: 5060

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/rowanhaoa/article/details/8591077

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>

using namespace std;

long long p[100000];
long long k[100000];

long long pows(long long n, long long m)//快速幂
{
    long long t = 1;
    while(m)
    {
        if(m%2 != 0)
        {
            t = (t*n)%9901;
            m--;
        }
        n = (n*n)%9901;
        m /= 2;
    }
    //cout<<t<<endl;
    return t;
}

long long mou(long long x,long long y)
{
    if(y==0)
        return 1;
    if(y%2==0)
        return (((mou(x,y/2-1)%9901)*((1+pows(x,y/2+1))%9901))%9901+pows(x,y/2)%9901)%9901;
    if(y%2!=0)
        return (mou(x,y/2)%9901)*((1+pows(x,y/2+1))%9901)%9901;
}
int main()
{
    long long m, n, i;
    while(~scanf("%lld %lld", &n, &m))
    {
        int j = 0;
        for(i = 2; i <= (int)sqrt(n*1.0); i += 2)
        {
            if(n%i==0)
            {
                p[j] = i;
                k[j] = 0;
                while(n%i==0)
                {
                    k[j]++;
                    n /= i;
                }
            }
            j++;
            if(i == 2)
            {
                i--;
            }
            if(n==1)
            {
                break;
            }
        }
        if(n != 1)
        {
            p[j] = n;
            k[j++] = 1;
        }
        //以上是分解质因数。
        for(i = 0; i < j; i++)
        {
            //printf("%d %d\n", p[i], k[i]);
            k[i] *= m;
        }
        long long sum = 1;
        for(i = 0; i < j; i++)
        {
            sum = sum * mou(p[i], k[i])%9901;
        }
        printf("%lld\n", sum);
    }
    return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值