-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNumberoftrailingzerosofN.cpp
More file actions
46 lines (39 loc) · 1 KB
/
NumberoftrailingzerosofN.cpp
File metadata and controls
46 lines (39 loc) · 1 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include<iostream>
#include <string>
#include<vector>
using namespace std;
long zeros(int n) {
int count = 0;
for (int i = 5; n / i >= 1; i *= 5) {
count += n / i;
}
return count;
}
int main()
{
cout << zeros(1000);
return 0;
}
/*Description:
Write a program that will calculate the number of trailing zeros in a factorial of a given number.
N! = 1 * 2 * 3 * ... * N
Be careful 1000! has 2568 digits...
For more info, see: http://mathworld.wolfram.com/Factorial.html
Examples
N Product N factorial Trailing zeros
6 1*2*3*4*5*6 720 1
12 1*2*3*4*5*6*7*8*9*10*11*12 479001600 2
Hint: You're not meant to calculate the factorial. Find another way to find the number of zeros.
Algorithms
Logic
Mathematics*/
// /> フ
// | n n 彡
// /`ミ_xノ
// / |
// / ヽ ノ
// │ | | |
// / ̄| | | |
// | ( ̄ヽ__ヽ_)__)
// \二つ
// ITS CAT FOR YOU