Happy 2004 hdu1452

Source: Internet
Author: User

Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 2021 Accepted Submission (s): 1474


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  number theory, reasoning is very troublesome: the main idea of the topic is to ask 2004^n all the factors of the sum. According to the unique decomposition theorem 2004= (2^2) *3*167, then 2004^n= (2^2n) * (3^n) * (167^n), and the conclusion: the factor of a factor and is an integrable function. Set F (x) for the factor of X and, then F (AB) =f (a) *f (b); F (2004^n) =f (2^2n) *f (3^n) *f (167^n). Continue on conclusion: If a number is a prime, then F (a^n) =1+a+a^2+a^3+.......a^n = (a^ (n+1)-1)/(A-1); considering 167%29=22, then f (2004^n) = (2^ (2n+1)-1) * (3^ (n+1)-1)/2 * (22^ (n+1)-1)/21; then upper inverse: (a*b/c)%mod=a%mod* B%MOD*INV (c); where INV (c) represents the smallest integer (C*INV (c))%mod=1. Mod=29, then INV (1) =1;INV (2) =15;INV (21) = 18; the primitive = (2^ (2n+1)-1) * (3^ (n+1)-1)%MOD*INV (2) *  (22^ (n+1)-1) *INV (21) 15*18% 29=9---------------The original (2^ (2n+1)-1) * (3^ (n+1)-1) * (22^ (n+1)-1) *9%29;
#include <iostream> #include <bits/stdc++.h>using namespace std;typedef long long ll;int ans=0;const int mod= 29;ll Quick_mod (ll k,ll N) {    ll res=1;    while (n>0)    {        if (n&1)        {            res= (res*k)%mod;        }        K=k*k%mod;        n>>=1;    }    res--;    if (res<0) res+=29;    return res;} int main () {    ll n;    while (~SCANF ("%lld", &n) &&n)    {        ans=quick_mod (2,2*n+1) *quick_mod (3,n+1) *quick_mod (22,n+1) * 9%mod;        printf ("%d\n", ans);    }    return 0;}

  

Happy 2004 hdu1452

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.