POJ 1845-Sumdiv (number theory, approximate number and formula, inverse element, High School Mathematics), poj1845-sumdiv
Description
Given A, B, calculate the sum of all the factors of A ^ B, and then MOD 9901
Input
A row has two integers, A and B.
Output
One row, an integer
Sample Input
2 3
Sample output
15
Prompt
For 100% of data: 0 <= A, B <= 50000000
This question must first come up with a factor and a formula.
F [a] = (1 + p1 + p1 ^ 2 + .... + p1 ^ q1) * (1 + p2 + p2 ^ 2 + .... + p2 ^ q2 )*...... * (1 + pn ^ 2 + ..... + pn ^ qn)
From this we know that this question needs to break down the prime factor (unique decomposition theorem ???
A ^ B can be directly divided into A, and the index of each split number is × B (this should all
So we can create a prime number table first ..
Because both a and B are at 50000000, it is enough for the calculator to calculate more than 7000 tables ..
Let's look at the factors and formulas. If it is too difficult to ask for help one by one, we will find that this is an equivalent sequence !!!
I believe everyone will use the proportional series formula...
The divisor may be a negative number, so the formula must be sorted up and down by X-1.
However, this may not be an integer, so we need to use the multiplication inverse element. (at that time, I got stuck here.
Here we will first post a well-written inverse multiplication element.
inline long long extend_gcd(long long a,long long b,long long &x,long long &y){ if(a==0&&b==0) return -1ll; if(b==0) { x=1ll; y=0ll; return a; } long long d=extend_gcd(b,a%b,y,x); y-=a/b*x; return d;}inline long long mod_reverse(long long a,long long n){ long long x,y,d=extend_gcd(a,n,x,y); if(d==1) return (x%n+n)%n; else return -1ll;}
Fast Power and Multiplication Modulo won't be mentioned
Post Code below
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #define ll long long ll vis[8000]={0}; ll ys[8000]={0},zs[8000]={0}; ll vis1[8000]={0}; ll ac[8000]={0}; using namespace std; ll n; ll qmod(ll i,ll j) { ll ans=1; while(j) { if(j&1) { ans*=i; ans%=9901; } i=i*i%9901; j>>=1; } return ans%9901; } void prime() { ll i,j,k=0; for(i=2;i<=7100;i++) { vis[i]=i; } i=2; while(i*i<=7100) { if(vis[i]!=0) { j=i<<1; while(j<=7100) { if(vis[j]!=0) { k++; } vis[j]=0; j=j+i; } } i++; } } int main() { ll k=1; ll i,j; ll A,b; ll a,n; cin>>a>>b; A=a; n=sqrt(a); prime(); for(i=2;i<=n;i++) { while((vis[i]!=0)&&(a%vis[i]==0)) { vis1[i]=1; ys[k]=vis[i]%9901; zs[k]++; a=a/vis[i]; } if(vis1[i]==1) { k++; } } k--; ll step=0; ll re=0,cf=0; if(a!=1&&a!=A) { ys[k+1]=a%9901; zs[k+1]=1; step=1; } else if(a==A) { ys[1]=a%9901; zs[1]=1; k=1; } if(step==1) { k++; } ll count=0; for(i=1;i<=k;i++) { if(zs[i]!=0) { zs[i]=zs[i]*b; count++; } } for(i=1;i<=count;i++) { ll a1=qmod(ys[i]%9901,zs[i]+1); a1=a1-1; ll temp=(ys[i]-1)%9901; ll a2=qmod(temp,9899); ac[i]=((a1%9901)*(a2%9901))%9901; } ll sum=ac[1]; for(i=2;i<=count;i++) { sum=((sum%9901)*(ac[i]%9901))%9901; } cout<<sum; }