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. Murano Weekly Meeting 2015.10.13

    Meeting time: 2015.October.13th 1:00~2:00 Chairperson:  Serg Melikyan, PTL from Mirantis Meeting sum ...

  2. 前端:移动端和PC端的区别

    在阿里的几次面试中,总是被问到移动端和PC端有什么区别,当时回答的时候主要是回答了在兼容性.网速.适配.页面布局等方面的不同,但是还是很不系统,所以这里做一个总结. 第一: PC考虑的是浏览器的兼容性 ...

  3. 安卓压力测试之monkey

    步骤: 1.把要测试的apk包放在 SDK-platfrom-tools下 2.配置adb.exe的环境变量 3.手机连接上电脑(虚拟机和真机只能连接一个) 4.运行:adb devices   查看 ...

  4. ajax多次请求的一个效果思路

    首先页面加载时候显示遮罩层 jQuery(function() { show_dialog(); //tianxie(); }); 定义一个全局数组,用于存放问题id var qar = []; 循环 ...

  5. 2.C#中的常用快捷键

    快速对齐代码: Ctrl+K+D:  快速对齐代码   (如果代码语法错误,就不能使用) Ctrl+Z:  撤销 Ctrl+S:保存   没事就Ctrl+S一下,防止因为电脑断电,代码全部丢失 Ctr ...

  6. SQL Server和ASP.NET的操作基本操作

    ado.net提供了丰富的数据库操作,这些操作可以分为三个步骤: 第一,使用SqlConnection对象连接数据库: 第二,建立SqlCommand对象,负责SQL语句的执行和存储过程的调用: 第三 ...

  7. JQuery基础知识==jQuery选择器

    选择器是jQuery的基础,在jQuery中,对事件处理.遍历DOM和Ajax操作都依赖于选择器 1. CSS选择器 1.1 CSS是一项出色的技术,它使得网页的结构和表现样式完全分离.利用CSS选择 ...

  8. 【踩坑】报错 non-static method xxx() cannot be referenced from a static context

    今天测试代码时遇到 Error:(6, 55) java: non-static method sayGoodbye() cannot be referenced from a static cont ...

  9. vue的组件传输

    vue的组件传输有四种,我个人觉得pubsub(订阅/发布)是最好用的,因为他不用去考虑关系,所以我们下面就只讲解pubsub吧 1) 优点: 此方式可实现任意关系组件间通信(数据)   首先我们需要 ...

  10. Java反射破坏单例模式

    今天电话面试的时候问到了,Google了一下 原出处: http://blog.csdn.net/lws332969674/article/details/8125893 一. Java中的反射技术可 ...