学校选拔赛

C - Factors of Factorial
求正因子个数,用到了正整数的唯一分解定理(算术基本定理)

代码

int f(int n) {
    ll a[1005];
    memset(a, 0, sizeof(a));
    for (int i = 2; i <= n; i++) {
        int tmp = i;
        for (int j = 2; tmp > 1; j++) {
            while (tmp % j == 0) {
                a[j]++;
                tmp /= j;
            }
        }
    }
    ll ans = 1;
    for (int i = 2; i <= n; i++) {
        //cout << a[i] << endl;
        ans = ans * (a[i] + 1) % mod;
    }
    return ans;
}
int main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n;
    cin >> n;
    cout << f(n) << endl;
}
  
原文地址:https://www.cnblogs.com/lingshi321/p/14716327.html