2019年海淀区青少年程序设计挑战活动小学组 T2
n的阶乘定义为n! = n ∗ (n − 1) ∗ (n − 2) ∗ ... ∗ 1。
n的双阶乘定义为n!! = n ∗ (n − 2) ∗ (n − 4) ∗ ... ∗ 2或n!! = n ∗ (n − 2) ∗ (n − 4) ∗ ... ∗ 1,取决于n的奇偶性。
但是阶乘的增长速度太快了,所以我们现在只想知道n!和n!!末尾的0的个数。
一个正整数n, n ≤ 10^7
两个整数, 分别为n!和n!!末尾0的个数。
10
2 1
5
1 0
#include<bits/stdc++.h>
using namespace std;
int n;
int one(int x){
int ans=0;
while(x>=5){
ans+=x/5;
x/=5;
}
return x;
}
int tow(int x){
int ans=0;
if(x%2==1){
return 0;
}
else{
x=x/2;
while(x>=5){
ans+=x/5;
x/=5;
}
}
}
int main(){
cin>>n;
cout<<one(n)<<" "<<tow(n);
}