当前位置:网站首页>[poj1845] sumdiv [number theory]

[poj1845] sumdiv [number theory]

2022-06-13 09:35:00 Ayane.

 Insert picture description here
l i n k link link

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=1npi1pici+11 So fast power multiplication p i − 1 p_i-1 pi1 The inverse element of

be aware 9901 9901 9901 Prime number if p i − 1 p_i-1 pi1 yes 9901 9901 9901 Multiple The inverse element will not exist here p i ≡ 1 ( m o d 9901 ) p_i\equiv1\pmod{9901} pi1(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;
}
原网站

版权声明
本文为[Ayane.]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202270530323793.html