poj 1845

来源:互联网 发布:模拟炒股软件手机版 编辑:程序博客网 时间:2024/06/11 20:18

Sumdiv
Time Limit: 1000MS Memory Limit: 30000KTotal Submissions: 16666 Accepted: 4164

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

#include <set>#include <cmath>#include <cstdio>#include <cstring>#include <iostream>using namespace std;#define LL long long#define mod 9901#define N 10005int A, B;int mul_pow(int a, int k){    int res = 1;    while(k)    {        if(k & 1) res = (res * a) % mod;        a = ((LL)a * a) % mod;        k >>= 1;    }    return res;}set<int> S;void doit(){    S.clear();    int t = A;    for(int i = 2; i <= t; i++)    while(t != i)    {        if(t % i == 0)        {            S.insert(i);            t /= i;        }        else break;    }    S.insert(t);}int sum(int a, int p){    if(a == 0) return 1;    if(p == 0) return 1;    if(p & 1) return (1 + mul_pow(a, p / 2 + 1)) * sum(a, p / 2) % mod;    else return ((1 + mul_pow(a, p / 2 + 1)) * sum(a, p / 2 - 1) + mul_pow(a, p / 2)) % mod;}int main(){    while(~scanf("%d%d", &A, &B))    {        if(A == 1 || A == 0)        {            printf("1\n");            continue;        }        doit();        int ans = 1;        for(set<int>::iterator it = S.begin(); it != S.end(); it++)        {            int num = 0;            while(A % (*it) == 0)            {                num++;                A /= (*it);            }            ans = (ans * sum(*it, num * B)) % mod;        }        printf("%d\n", ans);    }    return 0;}/*50000000 500000000 01 02 02 12 23 03 13 23 34 55 8*/


0 0
原创粉丝点击