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).
 
 
 
这道题目令我很不解的就是在等比求和的时候。大佬们分奇偶项数用二分递归求。而我的思路是乘法逆元*P1(P1^n  -1),也就是等比数列求和,在我出的数据中所得结果相同(rand随机出数)。。。不知道是什么原理
 
 
一开始想到的是A%mod^B,一举大数据直接炸。很快就想到唯一分解定理,然后等比求和,再然后就晾在等比求和上了。
AC代码:
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include "cstdio"
using namespace std;
#define ll long long
#define mod 9901
#define N 1000010
ll prime[N];
bool vis[N];
ll p[N];
ll pn=0;
ll POW(ll a,ll n)
{
ll base=a,ret=1;
while(n)
{
if(n&1) ret=(ret%mod*base)%mod;
base=(base*base)%mod;
n>>=1;
}
return ret%mod;
}
__int64 sum(__int64 p,__int64 n) //递归二分求 (1 + p + p^2 + p^3 +...+ p^n)%mod
{ //奇数二分式 (1 + p + p^2 +...+ p^(n/2)) * (1 + p^(n/2+1))
if(n==0) //偶数二分式 (1 + p + p^2 +...+ p^(n/2-1)) * (1+p^(n/2+1)) + p^(n/2)
return 1;
if(n%2) //n为奇数,
return (sum(p,n/2)*(1+POW(p,n/2+1)))%mod;
else //n为偶数
return (sum(p,n/2-1)*(1+POW(p,n/2+1))+POW(p,n/2))%mod;
}
int main()
{
for (int i = 2; i < N; i++) {
if (vis[i]) continue;
prime[pn++] = i;
for (int j = i; j < N; j += i)
vis[j] = 1;
}
ll a,b;
while(~scanf("%lld%lld",&a,&b))
{
memset(p,0,sizeof(p));
ll ans=1;
for(int i=0;prime[i]*prime[i]<=a;i++)
{
ll tem=0;
while(a%prime[i]==0)
{
tem++;
a/=prime[i];
}
if(tem)
{
p[prime[i]]=tem;
}
}
if(a!=1)
{
ll rev=POW(a-1,9899);
ll res=sum(a,b);
ans=ans*res%mod;
}
for(int i=0;i<pn;i++)
{ if(p[prime[i]])
{
ll rev=POW(prime[i]-1,9899);
ll res=sum(prime[i],p[prime[i]]*b);
ans=ans*res%mod;
}
}
cout<<ans<<endl;
}
}

  

poj_1845_Sumdiv的更多相关文章

  1. [20180828]exadata--豆腐渣系统的保护神.txt

    [20180828]exadata--豆腐渣系统的保护神.txt --//昨天看awr报表发现如下,时间8-9点报表,这个时间病房业务很少,主要门诊的业务: 1.awr报表情况:Top 10 Fore ...

随机推荐

  1. ApplicationContextAware的作用

    ApplicationContextAware其实我们看到---Aware就知道是干嘛用的了,就是属性注入的, 但是这个ApplicationContextAware的不同地方在于,实现了这个接口的b ...

  2. java连接数据库驱动代码综合共享

    1.Oracle8/8i/9i数据库(thin模式)Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();S ...

  3. HDU 2819 ——Swap——————【最大匹配、利用linker数组、邻接表方式】

     Swap Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status ...

  4. ASP.NET那点不为人知的事(一)

    http://www.cnblogs.com/OceanEyes/archive/2012/08/13/aspnetEssential-1.html#_label0 我们上网时,在浏览器地址输入网址: ...

  5. plupload2.1.2文件合并

    1.前端 (1)依赖文件: <link type="text/css" rel="stylesheet" href="~/Content/plu ...

  6. Android 5.0 以上监听网络变化

    大家好,大概有一个多月没有更新博客了,我是干什么去了呢?很明显,程序员当然要加班……这一次跟大家分享一下新项目的一些心得. 监听网络变化在开发中是经常用到的,例如我们断网有一些友好的提示,或者根据不同 ...

  7. centreon公司推出的check plugin pack

    文档 http://documentation.centreon.com/docs/centreon-plugins/en/latest/ (epel) # yum install nagios-pl ...

  8. mybatis返回boolean值时数据库返回null

    Servlet.service() for servlet [springDispatcherServlet] in context with path [/ms] threw exception [ ...

  9. python3 爬虫笔记(一)beautiful_soup

    很多人学习python,爬虫入门,在python爬虫中,有很多库供开发使用. 用于请求的urllib(python3)和request基本库,xpath,beautiful soup,pyquery这 ...

  10. Wampserver由橙变绿的解决过程

    因为C盘的内存问题,就重装了win7系统,那么就面临着很对软件要重新进行安装,安装wampserver时,再次遇到了服务器的图标一直是橙色的而不变绿色,安装包地址: http://download.c ...