zoukankan      html  css  js  c++  java
  • poj 1845 Sumdiv

     1 /**
     2 大意: 计算 a^b  的所有因子的和, 和mod 9901
     3 思路; 将a 进行质因子分解,那么所有因子的和为
     4 (2^0+ 2^1 + 2^2 +....+ 2^a1)*(3^0 + 3^1+..+ 3^a2)*.....
     5 注意: 求模n下a的逆,需要 gcd(a,n) =1,,所以此处不适合
     6 用二分求  0-n 次幂的和。。。 又遇到了一次。。。
     7 注意中间过程的取模。,,,不然会溢出。。
     8 **/
     9 
    10 #include <iostream>
    11 #include <cmath>
    12 #include <algorithm>
    13 #include <cstring>
    14 using namespace std;
    15 long long ddiv[50000];
    16 long long res[50000];
    17 int cnt;
    18 const int mod = 9901;
    19 void get_dr(long long n){
    20     memset(res,0,sizeof(res));
    21     long long m = (long long )sqrt(n+0.5);
    22     cnt =0;
    23     for(int i=2;i<=m;i++)if(n%i==0){
    24         ddiv[cnt] = i;
    25         while(n%i==0){
    26             res[cnt]++;
    27             n = n/i;
    28         }
    29         cnt++;
    30     }
    31     if(n>1){
    32         ddiv[cnt] = n;
    33         res[cnt]++;
    34         cnt++;
    35     }
    36 }
    37 
    38 long long  pow_mod(long long  a,long long  n){
    39     if(n==0)
    40         return 1;
    41     long long  c =1;
    42     a =a %mod;
    43     while(n){
    44         if(n&1)
    45             c =c*a%mod;
    46         a =a*a%mod;
    47         n>>=1;
    48     }
    49     return c;
    50 }
    51 
    52 long long sum (long long p,long long n){
    53         if(n==0)
    54             return 1; 
    55         if(n%2){     // 因为是从0开始的。。所以此处才是偶数的情况
    56             return (sum(p,n/2)*(1+pow_mod(p,n/2+1)))%mod;
    57         }
    58         else     // 奇数的情况
    59             return (sum(p,n/2-1)*(1+pow_mod(p,n/2+1))+pow_mod(p,n/2))%mod;
    60 }
    61 
    62 int main()
    63 {
    64     long long a,b;
    65     while(cin>>a>>b){
    66         if(b==0){
    67             cout<<1<<endl;
    68         }else if(a==0){
    69             cout<<0<<endl;
    70         }else{
    71             get_dr(a);
    72             //for(int i=0;i<cnt;i++)
    73             //    cout<<ddiv[i]<<endl;
    74             for(int i=0;i<cnt;i++){
    75                 res[i] *= b;
    76             }
    77             //for(int i=0;i<cnt;i++)
    78             //   cout<<res[i]<<endl;
    79             long long ans =1;
    80             for(int i=0;i<cnt;i++){
    81                 ans = (ans*(sum(ddiv[i],res[i]))%mod)%mod;
    82                 ans  =ans%mod;
    83             }
    84             ans = ans%mod;
    85             cout<<ans<<endl;
    86         }
    87     }
    88     return 0;
    89 }
  • 相关阅读:
    深入剖析Java中的装箱和拆箱
    JDBC(1)
    设计模式
    MySQL学习笔记(3)
    MySQL学习笔记(2)
    MySQL学习笔记(1)
    tomcat 部署项目出现Error thrown in preDeregister method
    JSP页面中的request.getContextPath()出现“ .... .. refers to the missing type String
    myEclipse 导入 jquery包为什么整个项目都会报错
    走楼梯
  • 原文地址:https://www.cnblogs.com/Bang-cansee/p/3724072.html
Copyright © 2011-2022 走看看