UVA11347 Multifactorials阶乘+组合

Posted 海岛Blog

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UVA11347 Multifactorials阶乘+组合相关的知识,希望对你有一定的参考价值。

A generalization of the factorials gives us multifactorials:
n! = n ∗ (n − 1) ∗ (n − 2) ∗ (n − 3). . .
n!! = n ∗ (n − 2) ∗ (n − 4) ∗ (n − 6). . .
n!!! = n ∗ (n − 3) ∗ (n − 6) ∗ (n − 9). . .
In general (there are k marks ‘!’):
n!! . . .! = n ∗ (n − k) ∗ (n − 2k). . .(n mod k), if k doesn’t divide n,
n!! . . .! = n ∗ (n − k) ∗ (n − 2k). . . k, if k divides n
    It this problem you are given a multifactorial, and you have to find the number of different dividers it has.
Input
The first line contains integer N (0 < N ≤ 500), it is number of tests. Each of the next N lines contains a multifactorial. Integer part of multifactorial is less or equal to 1000 and there are no more then 20 characters ‘!’.
Output
For each test case print line formatted like this: ‘Case i: a’. Where i is a test number, and a is the number of dividers in multifactorial. If number of dividers exceed 1018 print ‘Infinity’ (see examples).
Sample Input
3
5!
13!!
230!
Sample Output
Case 1: 16
Case 2: 64
Case 3: Infinity

问题链接UVA11347 Multifactorials
问题简述:计算整数n的多阶乘的因子个数。
问题分析:数学计算问题,不解释。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C++语言程序如下:

/* UVA11347 Multifactorials */

#include <bits/stdc++.h>

using namespace std;

int c[1000 + 1];

int main()
{
    int t, caseno = 0;
    string s;
    getline(cin, s);
    sscanf(s.c_str(), "%d", &t);
    while (t--) {
        getline(cin, s);

        int n, m = 0;
        sscanf(s.c_str(), "%d", &n);

        for (int i = s.size() - 1; i >= 0 && !isdigit(s[i]); i--)
            if (s[i] == '!') m++;

        memset(c, 0, sizeof c);
        for (int i = n; i >= 0; i -= m) {
            int p = i;
            for (int j = 2; j <= p; j++)
                while (p % j == 0) p /= j, c[j]++;
        }

        long long ans = 1;
        double sum = 0;
        for (int i = 0; i <= n; i++)
            ans *= c[i] + 1, sum += log10(c[i] + 1);

        printf("Case %d: ", ++caseno);
        if(ceil(sum) > 18)
            puts("Infinity");
        else
            printf("%lld\\n", ans);
    }

    return 0;
}

以上是关于UVA11347 Multifactorials阶乘+组合的主要内容,如果未能解决你的问题,请参考以下文章

uva 684 Integral Determinant 行列式求值

生成树计数

生成树计数

“n阶可导”和“n阶连续可导”的区别

n阶可导啥意思?

一阶矩阵乘以四阶矩阵怎么做