当前位置:网站首页>[poj1845] sumdiv [number theory]
[poj1845] sumdiv [number theory]
2022-06-13 09:35:00 【Ayane.】
analysis :
Consider the unique decomposition theorem A A A It can be expressed as ∏ i = 1 n p i c i \prod_{i=1}^{n} p_i^{c_i} ∏i=1npici
The sum of divisors is ( 1 + p 1 + p 1 2 + . . . + p 1 c 1 ) × ( 1 + p 2 + p 2 2 + . . . + p 2 c 2 ) × . . . × ( 1 + p n + p n 2 + . . . + p n c n ) (1+p_1+p_1^2+...+p_1^{c_1})\times(1+p_2+p_2^2+...+p_2^{c_2})\times...\times(1+p_n+p_n^2+...+p_n^{c_n}) (1+p1+p12+...+p1c1)×(1+p2+p22+...+p2c2)×...×(1+pn+pn2+...+pncn)
that A B A^B AB Can be expressed as ∏ i = 1 n p i c i × B \prod_{i=1}^n p_i^{c_i\times B} ∏i=1npici×B
At this time, the sum of the divisors is ( 1 + p 1 + p 1 2 + . . . + p 1 c 1 × B ) × ( 1 + p 2 + p 2 2 + . . . + p 2 c 2 × B ) × . . . × ( 1 + p n + p n 2 + . . . + p n c n × B ) (1+p_1+p_1^2+...+p_1^{c_1\times B})\times(1+p_2+p_2^2+...+p_2^{c_2\times B})\times...\times(1+p_n+p_n^2+...+p_n^{c_n\times B}) (1+p1+p12+...+p1c1×B)×(1+p2+p22+...+p2c2×B)×...×(1+pn+pn2+...+pncn×B)
Each part can be summed by an equal ratio sequence namely ∏ i = 1 n p i c i + 1 − 1 p i − 1 \prod_{i=1}^n\frac{p_i^{c_i+1}-1}{p_i-1} ∏i=1npi−1pici+1−1 So fast power multiplication p i − 1 p_i-1 pi−1 The inverse element of
be aware 9901 9901 9901 Prime number if p i − 1 p_i-1 pi−1 yes 9901 9901 9901 Multiple The inverse element will not exist here p i ≡ 1 ( m o d 9901 ) p_i\equiv1\pmod{9901} pi≡1(mod9901)
So the sum of the equal ratio series is ( 1 + 1 + 1 2 + . . . + 1 c n × B + 1 ) = c n × B + 1 (1+1+1^2+...+1^{c_n\times B+1})=c_n\times B+1 (1+1+12+...+1cn×B+1)=cn×B+1 The answer is ∏ i = 1 n c i × B + 1 \prod_{i=1}^n c_i\times B+1 ∏i=1nci×B+1
CODE:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define reg register
using namespace std;
typedef long long ll;
const ll Mod=9901,N=1e5+5;
ll A,B,p[N],c[N],tot,ans=1;
void calc(ll x)
{
for(int i=2;i*i<=x;i++)
{
if(x%i==0)
{
p[++tot]=i;
c[tot]=1;
x/=i;
while(x%i==0)
x/=i,c[tot]++;
}
}
if(x>1) p[++tot]=x,c[tot]=1;
}
ll ksm(ll a,ll k)
{
ll res=1;
while(k)
{
if(k&1) (res*=a)%=Mod;
(a*=a)%=Mod;
k>>=1;
}
return res;
}
int main(){
scanf("%lld%lld",&A,&B);
calc(A);
for(int i=1;i<=tot;i++)
{
int a=p[i],k=B*c[i];
((a-1)%Mod==0)?ans=ans%Mod*(k+1)%Mod:ans=ans%Mod*(ksm(a,k+1)%Mod-1+Mod)%Mod*ksm(a-1,Mod-2)%Mod;
}
printf("%lld",ans);
return 0;
}
边栏推荐
- (topological sorting +bfs) acwing 848 Topological sequence of digraph
- Jenkins接入Openldap用戶認證
- C#入门系列(十三) -- 初识结构体
- Acwing785. quick sort (sort+ quick sort + merge sort)
- LeetCode 6098. 统计得分小于 K 的子数组数目(前缀和+二分查找)
- LeetCode 5259. 计算应缴税款总额
- 【最全面详细解释】背包问题详解
- (state compression dp+ binary) acwing 91 Shortest Hamilton path
- LeetCode 343. 整数拆分
- Tree and binary tree: operation and storage structure of tree
猜你喜欢

(state compression dp+ binary) acwing 91 Shortest Hamilton path

Can the operation of the new BMW I3 meet the expectations of the famous products of the 3 series?

Solov2 source code analysis

C language: five custom types
![[51nod p2102] or subtraction and [bit operation]](/img/49/8cc722e5fb18de5ce30d58adb805db.jpg)
[51nod p2102] or subtraction and [bit operation]

BGP Federation +community

Yolov5 face learning notes

(dfs+ pruning + checkerboard problem +dood) acwing 843 N-queen problem

Classes and objects -- object model and this pointer

Exercise 7-7 string replacement (15 points)
随机推荐
A static variable is associated with a class and can be used as long as the class is in memory (the variable does not exist as long as your application terminates). (heap body, stack reference)
acwing 786. Number k
Standard template library (STL)
C language: minesweeping
VDD, dvdd, avdd, VCC, afvdd, dovdd, iovdd
Britain introduces food security plan to resist food supply crisis
C language: deep understanding of character functions and string functions (1)
Collection of articles on virtualization and cloud computing
acwing 789. Range of numbers (dichotomy + suitable for understanding dichotomy boundary)
JS【中高级】部分的知识点我帮你们总结好了
LeetCode 202. 快乐数
Resolve importerror:lib*** so--cannot open shared object file: No such... (pycharm/clion reports an error but the shell does not)
[51nod p2106] an odd number of times [bit operation]
Jenkins accédant à l'authentification de l'utilisateur openldap
LeetCode 343. 整数拆分
Lecture par lots de tous les fichiers vocaux sous le dossier
C language: five custom types
Heap
Summary of random number learning
Zigzag transformation
