Title meaning: All positive factors for 2004^x and 29 for redundancy
Analytical:
We use S (x) to denote the factor of X and:
The factor of 2 is 1,2,s (2) = 3;
The factor of 3 is 1,3,s (3) = 4;
The factor of 6 is 1,2,3,6,s (6) = 12;
Can be found: s (6) =s (2) *s (3) =3*4=12;
The factor of 4 is 1,2,4,,s (4) = 7;
The factor of 5 is 1,5,s (5) = 6;
The factor of 20 is 1,2,4,5,10,20,s (20) = 42;
Can be found: s (=s) (4) *s (5) =7*6=42;
S (25) =1+5+25=31
Look again S (=1+2+5+10+25+50=93=3*31=s) (2) *s (25)
This is called the integrable function in number theory.
Definition of integrable function in number theory: for an arithmetic function f (n) of positive integer n , if f (1) = 1, and when a,b coprime, F (ab) =f (a) f (B) ), which is called the integrable function in number theory. If for an integrable function f (n), even if a, B is not coprime, there is also F (AB) =f (a) f (b), it is said to be fully integrable .
Because 2004=2^2*3^1*167, so S (2004^x) =s (2^ (2x) *3^x*167^x) =s (2^ (2x)) *s (3^x) *s (167^x)
Make A=s (2^ (2x)), B=s (3^x), C=s (167^x), due to the congruence properties: 167=22 (mod29), 167 can be replaced by 22, C=s (22^x).
Also, if P is a prime number, then S (p^n) =p^0+p^1+p^2+......p^n, it can be found that this is a geometric series summation, so S (p^n) =p^0 (1-p^ (n+1))/(1-p) = (p^ (n+1)-1)/(p-1) ... ①
by ①: A=s (2^ (2x)) = (2^ (2x+1)-1)/1
B=s (3^x) = (2^ (x+1)-1)/2
C=s (22^x) = (22^ (x+1)-1)/21
and b and C can not be directly calculated, for the modulo operation has the following rules: 1. (a*b)%p= (a%p) * (b%p)
2. (A/b)%p= (a *b^ ( -1)%p)
b^ ( -1) (mod p) is the inverse of B, 2 has an inverse element of 15, because the inverse of 2*15%29=1%29,21 is 18 because 21*18%29=1%29
When calculating (A/b)%mod, it is often necessary to first calculate the inverse of the b%mod p (b has the inverse of the condition is gcd (b,mod) ==1, obviously the prime number must have an inverse element), and then by (a*p)%mod result c. Here B's inverse P satisfies (b*p)%mod=1
Here is a simple proof: (A/b)%mod=c; (b*p)%mod=1; = = "(A/b) * (b*p)%mod=c; = = "(a*p)%mod=c;
To find the inverse of the Euclidean can be achieved, assuming that the known b,mod, with the expansion of Euclid to find out Bx+mody=1 a set of solutions, both sides at the same time%mod can be bx%mod=1%mod, so x is the inverse of b%mod
The a= in the title (2^ (2x+1)-1)%29
B= (2^ (x+1)-1) *15%29
C= (22^ (x+1)-1)/*18%29
Ans=a*b*c%29
ABC three can be solved directly with a fast power, the code is as follows
#include <cstdio>#include<algorithm>#include<iostream>#include<cstring>#defineLL Long Longusing namespacestd; ll Pow_mod (ll a,ll N) {ll ans=1; A=a% in; while(n) {if(n&1) ans= (ans*a)% in; A=a*a% in; N>>=1; } returnans;}intMain () {LL x,a,b,c; while(SCANF ("%i64d", &x) &&x) {a= (Pow_mod (2,2*x+1)-1)% in; b= (Pow_mod (3, x+1)-1)* the% in; C= (Pow_mod ( A, x+1)-1)* -% in; printf ("%i64d\n", (a*b)% in*c% in); }}
HDU 1452 Happy 2004