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. redis数据类型及常用命令使用

    redis干啥的,一般人都知道,但很多人只知道是个缓存数据库,其它的就不知道了,本猿无能亦是如此,然知耻而后勇,我们该理一理这里边的一些逻辑,看看redis究竟是怎么一回事儿,能干啥,怎么做的,这样才 ...

  2. Java基础入门 - 标识符及其命名规范

    类名.变量名.方法名都称为标识符 标识符命名规范: 由字母(A-Z或a-z).数字.下划线(_)和美元符($)中的一种或多种组合而成 不可以数字开头 大小写敏感 关键字不能用作标识符 合法标识符如:D ...

  3. Spring课程 Spring入门篇 1-2Spring简介

    课程链接: 1 Spring是什么? 2 为什么是Spring 3 Spring的作用: 4 适用范围 1 Spring是什么? a 开源框架 b 轻量级的控制反转(Ioc)和面向切面编程(AOP)的 ...

  4. vue-样式问题

    问题: 今天在用vue开发单页面应用的时候,遇到一个问题,在A页面,直接刷新,页面的布局样式之类的是没有问题的,不过在B页面跳转到A页面,那么A页面有一些样式就不是预期的效果. 发现解决问题: 用调试 ...

  5. 转:解决Arcsde用户锁定的问题

    采用arcgis平台做GIS应用的人,可能偶尔碰到sde用户锁定(Arccatalog 或应用程序异常退出的时比较多)的问题,往往咱们解决的办法是重启sde服务.如果一个服务器上有多个连接时,重启服务 ...

  6. tfs2012安装

    今天正在配置tfs的服务器.要先安装net 3.5 ps1.要选择安装reportingservers 来启动报表功能.

  7. python3绘图示例5(基于matplotlib:正弦图等)

    #!/usr/bin/env python# -*- coding:utf-8 -*- import numpy as npimport pylab as pyimport matplotlib as ...

  8. Linux系统错误码对照表

    C Name Value Description EPERM 1 Operation not permitted ENOENT 2 No such file or directory ESRCH 3 ...

  9. 一起来看看IOS内存泄漏的一个问题

    很多iOS开发的朋友都是比较关心内存泄漏的问题,在实际的开发工作中首先我们需要知道程序有没有内存泄露,然后定位到底是哪行代码出现内存泄露了,这样才能将其修复.最简单的方法当然是借助于专业的检测工具,比 ...

  10. 西门子触摸屏利用VBScript脚本创建csv文件

    功能描述:利用VBScript脚本创建csv/txt文件 有时需要将PLC或运动控制器Simotion中的数据写到SD卡或U盘上.一种实现方法是,如果使用的是精致面板(comfort panel),可 ...