题目传送门

Sumdiv

Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 26041   Accepted: 6430

Description

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). 

Source


  分析:

  题意就是求A^B在mod 9901下的约数和。

  之前遇到过一个一模一样的题,直接分解质因数,把每一个质因数按照费马小定理对9901-1取模然后直接暴力计算就过了,但是在这里死活过不了。然后稍微推了一下发现这么做有BUG,因为9900不是质数,取模的时候会出错。

  然后翻了一下lyd的书,正解思路了解一下。

  同样先分解质因数,再由约数和定理ans=(1+q1+q1^2+...+q1^(c1*b))*(1+q2+q2^2+...+q2^(c2*b))*...*(1+qn+qn^2+...qn^(cn*b))可得,对于每一个质因数qi,求(1+qi+qi^2+...+qi^(ci*b))时,可以用等比数列的求和公式求,即(qi^(b*ci+1))/(qi-1),但是除法并不满足取模的分配律,所以就用逆元来代替。也就是求1/(qi-1)在模9901下的逆元。但是要注意,qi-1可能被9901整除,此时不存在逆元。不过可以发现,此时qi mod 9901=1,那么(1+qi+qi^2+...+qi^(b*ci))=1+1+1+...+1(b*ci+1个1),特判即可。

  Code:

//It is made by HolseLee on 21st June 2018
//POJ 1845
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<iomanip>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll mod=;
const ll N=5e6+;
ll A,B,q[N],f[N],ans,tot,cnt;
void fenjie()
{
for(ll i=;i*i<=A;i++){
if(A%i==){
q[++cnt]=i;
while(A%i==){
f[cnt]++;A/=i;}
}
}
if(A>)q[++cnt]=A,f[cnt]++;
}
inline ll power(ll x,ll y)
{
ll ret=;
while(y>){
if(y&)ret=(ret*x)%mod;
x=(x*x)%mod;y>>=;}
return ret;
}
void work()
{
fenjie();ans=;
for(int i=;i<=cnt;i++){
if((q[i]-)%mod==){
ans=(ans*(B*f[i]+)%mod)%mod;
continue;}
ll x=power(q[i],B*f[i]+);
x=(x-+mod)%mod;
ll y=power(q[i]-,mod-);
ans=(ans*x*y)%mod;
}
printf("%lld",ans);
}
int main()
{
cin>>A>>B;
work();return ;
}

最新文章

  1. 浅谈Android中的startActivityForResult和setResult方法
  2. Reactjs的Controller View模式
  3. java学习第17天(TreeSet HashSet)
  4. dns简介
  5. PHP用substr截取字符串出现中文乱码问题用mb_substr
  6. LinuxShell脚本攻略--第六章 B计划
  7. vlan知识
  8. 【转】 当程序崩溃的时候怎么办 part-1
  9. php部分学习笔记
  10. 将DataTable 数据插入 SQL SERVER 数据库
  11. UML九种图汇总
  12. vue-cli安装
  13. js 添加事件 attachEvent 和 addEventListener 的区别
  14. linux编译php gd扩展
  15. PHP开发工程师应该具备那些技术能力
  16. linux jdk 和tomcat环境变量配置
  17. LCA-RMQ+欧拉序
  18. css定位的各属性占位问题
  19. IE7下onclick事件失效的问题
  20. 关于JAVAweb的一些东西

热门文章

  1. 解决Sublime Install Package的There are no packages available for install问题(channel_v3.json)
  2. C11简洁之道:循环的改善
  3. consul windows安装
  4. 【BZOJ4816】【SDOI2017】数字表格 [莫比乌斯反演]
  5. bzoj 1594: [Usaco2008 Jan]猜数游戏——二分+线段树
  6. 【BZOJ】3502 PA2012 Tanie linie
  7. Fetch-新一代Ajax API
  8. js_参数的get传输,从一个页面到另外一个页面。
  9. G题 hdu 1466 计算直线的交点数
  10. 分类算法:决策树(C4.5)(转)