zoukankan      html  css  js  c++  java
  • hdu 1452 Happy 2004

    因子和:

    6的因子是1,2,3,6; 6的因子和是 s(6)=1+2+3+6=12;

    20的因子是1,2,4,5,10,20; 20的因子和是 s(20)=1+2+4+5+10+20=42;

    2的因子是1,2; 2的因子和是 s(2)=1+2=3;

    3的因子是1,3; 3的因子和是 s(3)=1+3=4;

    4的因子和是 s(4)=1+2+4=7;

    5的因子和是 s(5)=1+5=6;

    s(6)=s(2)*s(3)=3*4=12;

    s(20)=s(4)*s(5)=7*6=42;

    这是巧合吗?

    再看 s(50)= 1+2+5+10+25+50=93=3*31=s(2)*s(25),s(25)=1+5+25=31.

    这在数论中叫积性函数,当gcd(a,b)=1s(a*b)=s(a)*s(b);

    如果p是素数

    s(p^n)=1+p+p^2+...+p^n= (p^(n+1)-1) /(p-1) (1)

    hdu1452 Happy 2004

    计算 因子和 s(2004^X) mod 29 ,

    2004=2^2 *3 *167

    s(2004^X) ) = (s(2^2X))) * (s(3^X))) * (s(167^X)))

    167)=22;

    s(2004^X) ) = (s(2^2X))) * (s(3^X))) * (s(22^X)))

    a=s(2^2X)=(2^(2X+1)-1) //根据 (1

    b=s(3^X)= (3^(X+1)-1)/2 //根据 (1

    c=s(22^X)= (22^(X+1)-1)/21 //根据 (1

    %运算法则 1. (a*b) %p= ( a%p) *(b%p)

    %运算法则 2. (a/b) %p= ( a *b^(-1)%p)

    b^(-1)b的逆元素 (%p

    2的逆元素是15)) ,因为2*15=30 % 29=1 % 29

    21的逆元素是18)) ,因为21*18=378% 29 =1 % 29

    因此

    a=(powi(2,2*x+1,29)-1)% 29;

    b=(powi(3,x+1,29)-1)*15 % 29;

    c=(powi(22,x+1,29)-1)*18 % 29;

    ans=(a*b)% 29*c % 29;

     1 /*************************************************************************
     2     > File Name: xh.cpp
     3     > Author: XINHUA
     4     > Mail: 525799145@qq.com 
     5     > Created Time: 2013/7/22 星期一 19:54:04 新华
     6  ************************************************************************/
     7 
     8 #include<iostream>
     9 #include<stdio.h>
    10 #include<algorithm>
    11 #include<iomanip>
    12 #include<cmath>
    13 #include<string>
    14 #include<vector>
    15 #define ll __int64
    16 using namespace std;
    17 int pows(int a,int b)
    18 {
    19     int ans=1;
    20     while(b)
    21     {
    22         if(b&1) ans=ans*a%29;
    23         b>>=1;
    24         a=a*a%29;
    25     }
    26     return ans%29;
    27 }
    28 int main()
    29 {
    30     int n;
    31     while(cin>>n&&n)
    32     {        
    33         int a=(pows(2,2*n+1)-1)%29;
    34         int b=(pows(3,n+1)-1)*15%29;
    35         int c=(pows(22,n+1)-1)*18%29;
    36         printf("%d
    ",(((a*b)%29)*c)%29);
    37     }
    38     return 0;
    39 }
    View Code

  • 相关阅读:
    PAT (Advanced Level) 1010. Radix (25)
    PAT (Advanced Level) 1009. Product of Polynomials (25)
    PAT (Advanced Level) 1008. Elevator (20)
    PAT (Advanced Level) 1007. Maximum Subsequence Sum (25)
    PAT (Advanced Level) 1006. Sign In and Sign Out (25)
    PAT (Advanced Level) 1005. Spell It Right (20)
    PAT (Advanced Level) 1004. Counting Leaves (30)
    PAT (Advanced Level) 1001. A+B Format (20)
    PAT (Advanced Level) 1002. A+B for Polynomials (25)
    PAT (Advanced Level) 1003. Emergency (25)
  • 原文地址:https://www.cnblogs.com/xin-hua/p/3207534.html
Copyright © 2011-2022 走看看