# 数学高手也会爱上毒瘤数学题2## 题目背景MRC是一个数学高手。于是冷老师就让MRC来出几套题。!httpscdnluogucomcnuploadimage_hostingch3z2etwpng## 题目描述MRC经过思考想出了一道绝世毒瘤题:求$$1!! times 2!! times 3!! times cdots times n!!$$WXY:好好好你这么出题是吧好好好。作为凉心出题人W
代码示例
#include <iostream>
using namespace std;
int main() {
long long n;
cin >> n;
int count = 0;
for (int i = 1; i <= n; i+=2) {
long long num = i;
while (num % 5 == 0) {
count++;
num /= 5;
}
}
cout << count << endl;
return 0;
}
说明
这道题可以用一个循环来计算答案。由于只需要计算 $n!!$ 中每个数的因子中 $5$ 的个数,我们可以通过循环遍历 $n$ 的所有奇数,对每个数不断除以 $5$,直到无法整除为止,然后将除法的次数累加起来即可。
因为 $n!!$ 中每隔两个数会有一个 $5$,所以最终答案就是 $n$ 的奇数个数除以 $2$
原文地址: https://www.cveoy.top/t/topic/iOSi 著作权归作者所有。请勿转载和采集!