• Acwing 1294 樱花


    题意:

    给出一个整数n,求有多少个正整数对(x, y)满足$frac{1}{x}$ + $frac{1} {y}$  = $frac{1} {n!}$.答案对$10^9+7$取模

    思路:

    公式推导:

    原式 = $frac{x + y}{xy}$ = $frac{1}{n!}$  

     $xn! + yn! = xy$

    $xn! = xy - yn!$

    $y = frac{xn!}{x - n!}$

    则,$y = frac{xn!}{x - n!} = frac{(x - n! + n!)n!}{x - n!} = n! + frac{n! ^ 2}{x - n!}$

    问题转变为$n!^2$的约数个数

    Code:

    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    
    using namespace std;
    
    typedef long long ll;
    
    const int N = 1e6 + 10;
    const int mod = 1e9 + 7;
    
    int n;
    int primes[N], cnt;
    bool st[N];
    
    void get(int n){
        for(int i = 2; i <= n; i ++){
            if(!st[i]){
                primes[cnt ++] = i;
            }
            for(int j = 0; primes[j] <= n / i; j ++){
                st[i * primes[j]] = true;
                if(i % primes[j] == 0){
                    break;
                }
            }
        }
    }
    
    int main(){
        cin.tie(0);
        cout.tie(0);
    
        get(N);
    
        cin >> n;
    
        int ans = 1;
        for(int i = 0; i < cnt; i ++){
            int s = 0, p = primes[i], num = 1;
            while(n >= (ll)num * p){
                num *= p;
                s += n / num;
            }
            ans = (ll)ans * (2 * s + 1) % mod;
        }
    
        cout << ans << endl;
    
        return 0;
    }
  • 相关阅读:
    总结
    kafka
    kafka前传 JMS
    currentHashMap
    mapPartitionsWithIndex foreachPartitionAsync foreachPartition
    hbase
    hive
    zookeeper kafka storm
    flume的简单使用
    spring-data-jpa
  • 原文地址:https://www.cnblogs.com/jungu/p/13387650.html
Copyright © 2020-2023  润新知