博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
luogu 1593 因子和
阅读量:4577 次
发布时间:2019-06-08

本文共 1062 字,大约阅读时间需要 3 分钟。

因子和

题目描述

输入两个正整数a和b,求\(a^b\)的因子和。结果太大,只要输出它对9901的余数。

解法

基本算数定理,每一个数都可以被分解成一系列的素数的乘积,然后你可以分解出因数了。

如何求出因数和呢?我们发现是等比数列,之后我们上等比数列求和公式就好了
\[ S_n = \frac{a_1 \times (1-q^n)}{1-q}=\frac{p_{i}^{c_i+1} -1}{p_i -1} \]
其中我们可以用快速幂和逆元求出来了

#include 
#include
#include
#include
#include
#include
#define LL long longusing namespace std;const LL mod = 9901;LL ksm(LL x,LL y) { LL z=1; while(y) { if(y&1) z=(z*x)%mod; y>>=1; x=(x*x)%mod; } return z%mod;}LL to[2],get=1;int main() { LL a=0,b=0,tmp,lim; scanf("%lld%lld",&a,&b); lim=sqrt(a); for(LL i = 2; i <= lim; i ++) { if(!(a%i)) { tmp=0; while(!(a%i)) { a/=i; tmp++; } to[1]=(tmp*b+1); if(i%mod==1) get=get*(tmp+1)%mod; else { to[0]=i%mod; get=get*(ksm(to[0],to[1])-1)*ksm(to[0]-1,mod-2)%mod; } } } if(a!=1) { to[1]=(b+1); if(a%mod==1)get=get*(b+1)%mod; else { to[0]=a%mod; LL k=(ksm(to[0],to[1])-1)*ksm(to[0]-1,mod-2)%mod; get=get*k%mod; } } printf("%lld",get); return 0;}

转载于:https://www.cnblogs.com/ifmyt/p/9805337.html

你可能感兴趣的文章
day11.初识函数
查看>>
树莓派:一个关于教育的故事
查看>>
Granting and Managing Item Level Permission using SharePoint2013 Designer Workflow
查看>>
[模板][P3796]AC自动机(加强版)
查看>>
Leetcode算法题库Python版本题目9-回文数
查看>>
Error message "there are no property pages for the selection"
查看>>
1x1的卷积核有什么作用
查看>>
洛谷1230
查看>>
ubuntu安装 scala
查看>>
25最短路径之Dijkstra算法
查看>>
JavaScript函数节流和函数防抖的原理与区别
查看>>
查看指定应用W级别以上的log日志
查看>>
postman接口测试实例
查看>>
.Net Core下如何管理配置文件
查看>>
常用WebService一览表
查看>>
模板方法模式(TemplateMethod)
查看>>
常用正则表达式
查看>>
valgrind的callgrind工具进行多线程性能分析
查看>>
ListBox禁止默认的上下快捷键
查看>>
freetype
查看>>