poj 1845

Sumdiv
Time Limit: 1000MS Memory Limit: 30000K
Total 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


#include <set>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;
#define LL long long
#define mod 9901
#define N 10005

int 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 50000000
0 0
1 0
2 0
2 1
2 2
3 0
3 1
3 2
3 3
4 5
5 8

*/


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值