HDU 1452 Happy 2004 (Fast Power + modulo multiplication inverse)

Source: Internet
Author: User

Problem Descriptionconsider A positive integer x,and let S is the sum of all positive integer divisors of 2004^x. Your job is to determine s modulo (the rest of the division of S by 29).
Take X = 1 for an example. The positive integer divisors of 2004^1 are 1, 2, 3, 4, 6,, 167, 334, 501, 668, 1002 and 2004. Therefore s = 4704 and s modulo are equal to 6.

Inputthe input consists of several test cases. Each test case is contains a line with the integer x (1 <= x <= 10000000).
A test Case of X = 0 indicates the end of input, and should not being processed.

Outputfor each test case, in a separate line, please output the result of S modulo 29.

Sample Input1100000

Sample Output610

Test instructions: Find the value of 2014^x%29.

Fast power and modulus multiplication inverse element. Multiply inverse: x= (1/b)%m. Find the value of x. X*b=k*m+1, which is k to the minimum positive integer, x is also an integer. That B can be divisible by k*m+1.

1#include <cstdio>2#include <cstring>3 using namespacestd;4 intF1 (intXinty)5 {6     intans=1;7      while(y)8     {9         if(y&1) ans=ans*x% in;Tenx=x*x% in; Oney>>=1; A     } -     returnans; - } the intF2 (intx) - { -     intI=1; -      while(i) +     { -         if(( in*i+1)%x==0) Break; +i++; A     } at     return( in*i+1)/x; - } - intMain () - { -     intx,a,b,c; -      while(~SCANF ("%d",&x)) in     { -         if(!x) Break; toA= (F1 (2,2*x+1)-1)% in; +C= (((F1 (3, x+1)-1)% in) *f2 (2))% in; -B= (((F1 ( A, x+1)-1)% in) *f2 ( +))% in; theprintf"%d\n", (a*b*c)% in); *     } $     return 0;Panax Notoginseng}

HDU 1452 Happy 2004 (Fast Power + modulo multiplication inverse)

Related Article

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.