Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=1452
Title Description: let you beg 2004^x of all factors of the sum, modulo 29
Solution thinking: First of all, the 2014 quality factor decomposition, 2^2 * 3 * 167, so the number of all factors is (2x+1) * (x+1) * (x+1), we list the formula, equivalent to a spatial Cartesian coordinate system, we first add the X, y plane points, plus the z axis, the final formula
Ans = (3^ (x+1)-1) * (167^ (x+1)-1) * (2^ (2*x+1)-1)/332 can, pay attention to inverse element
Code:
#include <iostream>#include<cstdio>#include<string>#include<vector>#include<cstring>#include<iterator>#include<cmath>#include<algorithm>#include<stack>#include<deque>#include<map>#defineLson L, M, rt<<1#defineRson m+1, R, rt<<1|1#defineMem0 (a) memset (A,0,sizeof (a))#defineSCA (x) scanf ("%d", &x)#defineDe printf ("=======\n")typedefLong Longll;using namespacestd;Const intMoD = inll Q_power (ll A, ll b) {LL ret=1; while(b) {if(B &1) ret = ret * A%MoD; b>>=1; A= A * A%MoD; } returnRet%MoD;} ll EXGCD (ll A, ll B, LL&x, LL &y) {if(b = =0) {x=1; Y=0; returnA; } Else{LL ret= EXGCD (b, a%b, x, y); LL TMP=x; X=y; Y= TMP-A/b *y; returnret; }}LL INV (ll a) {ll x, y; EXGCD (A, mod, x, y); return(x% mod + MoD)%MoD;}intMain () {ll x; while(SCANF ("%lld", &x) = =1&&x) {ll ans; ll a= Q_power (3, x+1); LL b= Q_power (167, x+1); ll c= Q_power (2,2*x+1); Ans= (a*b*c-a*c-b*c+c-a*b+a+b-1) * INV (332) %MoD; printf ("%lld\n", ans); } return 0;}View Code
Thinking: Through the subject of their own understanding of the inverse of a bit deeper, has been ambiguous before .... And this problem is a routine, the problem is more than just
A*b*c-a*c-b*c+c-a*b+a+b
A*b*c-a*c-b*c+c-a*b+a+b
A*b*c-a*c-b*c+c-a*b+a+b
HDU 1452 Happy 2004 number theory