• 约数之和


    众所周知计算正整数(A)约数和的方法是:

    (A)质因数分解为(p_1^{c_1} p_2^{c_2} p_3^{c_3} cdots p_m^{c_m})

    (A)的约数和即为((1 + p_1 + p_1^2 + cdots + p_1^{c_1}) * (1 + p_2 + p_2^2 + cdots + p_2^{c_2}) * (1 + p_2 + p_2^2 + cdots + p_2^{c_2}) * cdots * (1 + p_m + p_m^2 + cdots + p_m^{c_m}))

    记得李煜东给了个分治求等比数列求和的方法, 大概就是将利用数列是等比的, 利用较短数列的和求出较长数列的和, 具体实现有一些细节.

    
    #include<bits/stdc++.h>
    using namespace std;
    
    #define int long long
    
    const int mod = 9901;
    
    int ksm(int a, int b)
    {
        int res = 1; a%=mod;
        for(;b;b>>=1, a=(a*a)%mod)
            if(b & 1) res = (res * a) % mod;
        return res % mod;
    }
    
    int sum(int p, int c)
    {
        if(c == 1) return 1;
        int smer = sum(p, c>>1);
        int now = (smer + smer * ksm(p, c>>1) % mod) % mod;
        if(c&1) now = (now + ksm(p, c-1)) % mod;
        return now % mod;
    }
    
    signed main()
    {
        
        int a, b; cin >> a >> b;
        
        if(!a)
        {
            cout << 0;
            return 0;
        }
        
        int ans = 1;
        for(int i=2; i<=a; ++i)
        {
            int s = 0;
            while(a%i == 0) ++s, a/=i;
            ans = ans * sum(i, s * b + 1) % mod;
        }
        
        cout << ans % mod;
        return 0;
        
    }
    
    
  • 相关阅读:
    Splay 区间操作(二)
    P1351 联合权值
    Splay 区间操作
    P1801 黑匣子_NOI导刊2010提高(06)
    P3620 [APIO/CTSC 2007]数据备份
    T25990 [Wind Festival]Running In The Sky
    P1484 种树
    P4177 [CEOI2008]order
    题解 P2762 【太空飞行计划问题】
    dalao&话
  • 原文地址:https://www.cnblogs.com/tztqwq/p/12238758.html
Copyright © 2020-2023  润新知