/*
Poj 1845 Sumdiv
D(A)表示A的所有约数和,p表示A的素因数
A = pow(p1,n1)*pow(p2,n2)*...*pow(pn,nn)
D(A) =( 1 + pow(p1,1) + pow(p1,2) + ... + pow(p1,n1))*
( 1 + pow(p2,1) + pow(p2,2) + ... + pow(p2,n2))*
...
( 1 + pow(pn,1) + pow(pn,2) + ... + pow(pn,nn))
*/
#pragma comment(linker, "/STACK:102400000,102400000")
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <string>
#include <ctime>
#include <cmath>
#define CLR(a,v) memset(a,v,sizeof(a))
using namespace std;
typedef __int64 ll;
const int N = 1e4 + 5;
ll en[N] , e[N];
ll Mod = 9901;
ll multMod(ll a,ll b) // a*b % Mod
{
ll res = 0,base = a;
while(b)
{
if(b&1)
(res += base) %= Mod;
(base <<= 1) %= Mod;
b >>= 1;
}
return res;
}
ll powerMod(ll a,ll n)// a^n % Mod
{
ll res = 1 , base = a;
while(n)
{
if(n&1)
res = multMod(res,base);
base = multMod(base,base);
n >>= 1;
}
return res;
}
ll solve(ll a,ll n) // (a + a^2 + a^3 + a^4 + ... + a^n) % Mod
{
if(n == 1)
return a;
ll halfsum = solve(a,n >>1);
if(n&1)
{
ll half = powerMod(a,n+1 >>1);
return (halfsum + half + multMod(half,halfsum)) % Mod;
}
else
{
ll half = powerMod(a,n >>1);
return (halfsum + multMod(half,halfsum)) % Mod;
}
}
int main(){
ll A,B;
while(cin >> A >> B){
if(A<=1 || !B){
cout << 1 << endl; continue;
}
int bound = ceil(sqrt(A*1.0)) , cnt = 0;
for(int i = 2 ; i < bound ; i++){
if(A%i == 0){
en[cnt] = 0;
e[cnt] = i;
while(A%i == 0){
A /= i;
en[cnt]++;
}
}else continue;
en[cnt++] *= B;
}
if(A>1){
e[cnt] = A; en[cnt++] = B;
}
ll ans = 1;
for(int i = 0 ; i < cnt ; i++){
ll tmp = solve(e[i],en[i])+1;
ans = ans*(tmp) % Mod;
}
cout << ans << endl;
}
return 0;
}
Poj 1845 Sumdiv -- A的所有约数和
最新推荐文章于 2019-05-29 12:11:39 发布