POJ 1845Sumdiv(数论)

来源:互联网 发布:国内论文数据库 编辑:程序博客网 时间:2024/05/17 07:54

Sumdiv

Time Limit: 1000MS Memory Limit: 30000KTotal 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
原创粉丝点击