• HDU1452 Happy 2004 (因子和)


    Happy 2004

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)



    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
     
    Source
     
    Recommend
    lcy   |   We have carefully selected several similar problems for you:  1695 1573 1788 1060 1370
    首先2004 = 2*2*3*167
    然后,利用因子和是积性函数的性质(蒟蒻准备专门写一篇持续更新的有关积性函数证明及学习的文章):
    σ(2004^x) =  σ(2^2x) * σ (3^x) * σ(167^x) Mod 29
    ∵167≡22(Mod29)
    故σ(2004^x) =  σ(2^2x) * σ (3^x) * σ(22^x) Mod 29
                       =  [2^(2x+1)-1][3^(x+1)-1]/2*[22^(x+1)-1]/21
    因为2的模29乘法逆元为15 ,22的模29乘法逆元为18
    故σ(2004^x)  =  [2^(2x+1)-1][3^(x+1)-1]*15*[22^(x+1)-1]*18
    即可用快速幂求解
     1 #include<set>
     2 #include<queue>
     3 #include<vector>
     4 #include<cstdio>
     5 #include<cstdlib>
     6 #include<cstring>
     7 #include<iostream>
     8 #include<algorithm>
     9 using namespace std;
    10 const int Mod = 29;
    11 #define Rep(i,n) for(int i=1;i<=n;i++)
    12 #define For(i,l,r) for(int i=l;i<=r;i++)
    13 
    14 int ans,x;
    15 
    16 int quickpow(int m,int n){
    17     int ans=1;
    18     while(n){
    19         if(n&1) ans=(ans*m)%Mod;
    20         m=(m*m)%Mod;
    21         n>>=1; 
    22     }
    23     return ans%Mod;
    24 }
    25 
    26 int main(){
    27     while(scanf("%d",&x),x){
    28         int ans=0;
    29         ans=(quickpow(2,2*x+1)-1)%Mod;
    30         ans=ans%Mod*(quickpow(3,x+1)-1)*15%Mod;
    31         ans=ans%Mod*(quickpow(22,x+1)-1)*18%Mod;
    32         printf("%d
    ",ans%Mod);
    33     }
    34     return 0;
    35 }
    View Code
  • 相关阅读:
    sql语句常考知识点总结
    服务器搭建
    软件测试面试题
    linux常用命令
    kibana常用查询删除语法
    python从kafka消费数据
    foxmail客户端,写邮件窗口弹不出来
    JMeter学习——测试文件下载
    python中取两个列表中不同的元素
    MySQL主从复制
  • 原文地址:https://www.cnblogs.com/zjdx1998/p/4020959.html
Copyright © 2020-2023  润新知