blob: ba8c614fa10555610df7f76150c33792064ccd53 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
#include <stdlib.h>
#include <iostream>
#include <string>
using namespace std;
const unsigned long long fact(const int n) {
unsigned long long res = 1;
for (int i = 2; i <= n; i++)
res *= i;
return res;
}
const int num_trailing_zeros(const unsigned long long n) {
int cnt = 0;
unsigned long long pwr = 10;
while (n % pwr == 0) {
cnt++;
pwr *= 10;
}
return cnt;
}
int main(int argc, char *argv[]) {
int n = atoi(argv[1]);
unsigned long long f = fact(n);
int z = num_trailing_zeros(f);
string zeros = (z == 1) ? "zero" : "zeros";
cout << n << " as N! = " << f << " has " << z << " trailing " << zeros << endl;
}
|