当前位置:网站首页>[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;
}
边栏推荐
- 删除软链接
- C language: Address Book
- Heap
- Leetcode points to offer 30 Stack containing min function
- 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)
- C language: five custom types
- Exercise 7-7 string replacement (15 points)
- Solov2 source code analysis
- @Value不生效及extend/implement其他类无法注入bean的手动注入
- LeetCode 5259. Calculate the total tax payable
猜你喜欢

C language: five custom types

turtle库的使用数字时钟模拟时钟动态显示

Trees and binary trees: traversal of binary trees

Exploitation of competitive loopholes in attacking and defending world PWN play conditions

Acwing785. quick sort (sort+ quick sort + merge sort)

Dynamic display of analog clock using digital clock in turtle Library

Classes and objects -- polymorphic

Tree and binary tree: storage structure of binary tree

C language: Simulated Implementation of library function strcpy

Online debugging tool Arthas advanced
随机推荐
7-3 virus traceability (20 points)
Trees and binary trees: Construction of binary trees
[51nod p3216] Award [bit operation]
@Value does not take effect and extend/implement other classes cannot inject beans manually
Jenkins access openldap user authentication
Exercise 7-7 string replacement (15 points)
Standard template library (STL)
LeetCode 5270. 网格中的最小路径代价(动态规划)
C language: five custom types
LeetCode 剑指 Offer 30. 包含min函数的栈
acwing 789. Range of numbers (dichotomy + suitable for understanding dichotomy boundary)
LeetCode 343. 整数拆分
[pytorch environment installation]
LeetCode 202. Happy number
Online debugging tool Arthas Foundation
LeetCode 1. Sum of two numbers
Delete soft link
Tree and binary tree: operation and storage structure of tree
马斯克的「元宇宙」梦
acwing 786. Number k
