-
-
Notifications
You must be signed in to change notification settings - Fork 298
/
Copy path172.cpp
41 lines (37 loc) · 998 Bytes
/
172.cpp
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
__________________________________________________________________________________________________
sample 4 ms submission
class Solution {
public:
int trailingZeroes(int n) {
int count=0;
long long i=5;
while(n/i)
{
count+=n/i;
i=i*5;
}
return count;
}
};
__________________________________________________________________________________________________
sample 8232 kb submission
class Solution {
public:
int trailingZeroes(int n) {
if(n<5) return 0;
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int ans = 0;
for(long i=5 ; i<=n ; i+=5){
if(i>n) break;
int temp = i;
while(temp%5 == 0){
ans++;
temp/=5;
}
}
return ans;
}
};
__________________________________________________________________________________________________