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. vue进阶 --- 实例演示

    这篇博客将通过一个实例来对vue构建项目的过程有一个了解. 主要用到的知识点如下所示: vue-router 2.0路由配置 router-view 和 router-link的使用 transiti ...

  2. linux 统计TCP 连接各状态总数

    netstat  -n|awk '/^tcp/ {++s[$NF]} END {for(k in s) print k, s[k]}' 以前经常只是从笔记中复制下, 这次打算 研究下 awk 语法 . ...

  3. mysql中操作符LIKE与通配符%的使用

    mysql中通配符%用来通配其他字符,操作符LIKE用来查询字段中存在相同的字符 SELECT t.userId,t.cellphone,t.idNo,t.* FROM t_person t WHER ...

  4. 切图技巧——PS篇

    1.选框工具这里可以选择增加选区.减少选区 ==> 2.存储为web格式 1)JPG:一般用于大图 2)gif:可作动图,与png-8基本一样,不支持半透明 3)png-8:不支持动图,不支持半 ...

  5. GitKraken使用教程-基础部分(2)

    3. 修改用户名 为了方便项目中代码的管理,需要重新编辑用户名. 点击右上角的图像即可看到如下图 3‑1所示的下拉菜单,鼠标悬于Profile上,会出现一个Edit按钮. 图 3‑1 编辑个人信息 点 ...

  6. 动态配置log4j2.xml日志输出文件的位置

    目标:根据启动jar时传进main()的参数动态修改日志位置 一.修改启动项 MainMapLookup.setMainArguments(args);注:不要在lookup设置之前初始化log(如: ...

  7. stl::iterator汇总

    STL——iterator 一.概述Iterator(迭代器)模式又称Cursor(游标)模式, 根据STL中的分类,iterator包括:Input Iterator:只能单步向前迭代元素,不允许修 ...

  8. 会话状态在此上下文中不可用HttpModule中无法访问Session原因

    写了一个自定义HttpModule,但始终访问不了Session,代码如下: public class RouteModule : IHttpModule, System.Web.SessionSta ...

  9. css改变透明背景png图片的图标颜色

    HTML: <p><strong>原始图标</strong></p> <i class="icon icon-del"> ...

  10. ArcGisJS的layers-add-result事件总结

    map.on("layers-add-result", initEditing);当地图控件中的所有图层加载完毕之后触发. 注意图层加载完成后返回的的结果:event. funct ...