zoukankan      html  css  js  c++  java
  • Happy 2004 hdu1452

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 2021    Accepted Submission(s): 1474


    Problem Description
    Consider a positive integer X,and let S be the sum of all positive integer divisors of 2004^X. Your job is to determine S modulo 29 (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, 12, 167, 334, 501, 668, 1002 and 2004. Therefore S = 4704 and S modulo 29 is equal to 6.
     
    Input
    The input consists of several test cases. Each test case contains a line with the integer X (1 <= X <= 10000000). 

    A test case of X = 0 indicates the end of input, and should not be processed.
     
    Output
    For each test case, in a separate line, please output the result of S modulo 29.
     
    Sample Input
    1 10000 0
     
    Sample Output
    6 10
     
    数论题,推理挺麻烦的:
    题目的大意是说求2004^n的全部因子之和。
    根据唯一分解定理2004=(2^2)*3*167,则2004^n=(2^2n)*(3^n)*(167^n);
    又有结论:一个因数的因子和是一个积性函数。设f(x)为x的因子和,则f(ab)=f(a)*f(b);
    则f(2004^n)=f(2^2n)*f(3^n)*f(167^n).
    继续上结论:如果一个数是素数,那么f(a^n)=1+a+a^2+a^3+.......a^n=(a^(n+1)-1)/(a-1);
    考虑到 167%29=22;
    则f(2004^n)=(2^(2n+1)-1) * (3^(n+1)-1)/2 * (22^(n+1)-1)/21;
    接着上逆元: (a*b/c)%mod=a%mod*b%mod*inv(c);
    其中inv(c)表示(c*inv(c))%mod=1的最小整数. mod=29,则inv(1)=1;
    inv(2)=15;inv(21)=18;
    则原式=(2^(2n+1)-1)*(3^(n+1)-1)%mod*inv(2)* (22^(n+1)-1)*inv(21)
    15*18%29=9---------------则原式(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
    ",ans);
        }
        return 0;
    }
    

      

  • 相关阅读:
    原生JS实现日历
    重复的事情让机器来做,简化的思想
    Ext3.1的一些使用讨论
    JS使用Crypto实现AES/ECS/zero-padding加密
    一些提升效率的小知识
    一些很有意思的JS现象
    Tiny Linux -- tce-load
    python sqlalchemy mysql 自动映射
    python 反射
    python 动态导包
  • 原文地址:https://www.cnblogs.com/zyf3855923/p/8777897.html
Copyright © 2011-2022 走看看