当前位置:网站首页>[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;
}
边栏推荐
- (dfs) acwing 842. Arrange numbers
- Online debugging tool Arthas advanced
- C language: deep understanding of character functions and string functions (2)
- I have summarized the knowledge points of JS [intermediate and advanced] for you
- Attack and defense world PWN shell
- [pytorch environment installation]
- Jenkins接入Openldap用户认证
- JS【中高级】部分的知识点我帮你们总结好了
- acwing 786. Number k
- Tree and binary tree: application of binary tree traversal
猜你喜欢
(dijkstra+ shortest path + edge traversal 0 (m)) acwing 850 Dijkstra finding the shortest path II
【pytorch环境安装搭建】
Overview of common layers of image recognition neural network (under update)
[51nod p3111] xiaoming'ai intercepts [Las]
Yolov5 face learning notes
Trees and binary trees: Construction of binary trees
turtle库的使用数字时钟模拟时钟动态显示
Classes and objects -- object model and this pointer
Acwing 787. Merge sort
[pytorch environment installation]
随机推荐
C language: dynamic memory management
Opencv face recognition of ros2 foxy~galactic~humble
Trees and binary trees: the concept of binary trees
turtle库的使用数字时钟模拟时钟动态显示
LeetCode 343. integer partition
LeetCode 322. Change
LeetCode 6095. Strong password checker II
C language: file operation
(dijkstra+ shortest path + edge traversal 0 (m)) acwing 850 Dijkstra finding the shortest path II
LeetCode 6096. Success logarithm of spells and potions (binary search)
Online debugging tool Arthas advanced
Biden: hope to sign the bipartisan gun safety reform bill as soon as possible
Jenkins接入Openldap用户认证
LeetCode 202. Happy number
LeetCode 201. Digit range bitwise AND
Summary of string, vector and array learning
攻防世界-PWN-shell
BGP Federation +community
LeetCode 1. Sum of two numbers
MOOC week 8 programming exercise 1