HDU 1452 Happy 2004 number theory

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.