-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcombinationzero
More file actions
100 lines (81 loc) · 1.47 KB
/
combinationzero
File metadata and controls
100 lines (81 loc) · 1.47 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
문제
n명의 사람중 m명을 순서에 상관없이 뽑는 경우의 수를 조합이라고 하며 nCm으로 나타낸다.
nCm은 수식으로 n!/m!(n-m)! 으로 구할 수 있다. (5! = 12345)
n과 m이 주어졌을때 nCm의 끝자리 0의 개수를 출력하는 프로그램을 작성하시오.
입력
첫째 줄에 정수 n, m(0≤m≤n≤1,000,000)이 들어온다.
출력
첫째 줄에 0의 개수를 출력한다.
예제 입력
25 12
예제 출력
2
#include <stdio.h>
int main() {
int n,m;
scanf("%d %d",&n,&m);
int cnt1,cnt2;
cnt1=0;
cnt2=0;
int mother=0;
if(m>(n-m)){
mother=n-m;
}
else{
mother=m;
}
for(int i=n;i>n-mother;i--){
if(i%5==0){
cnt1++;
}
if(i%(5*5)==0){
cnt1++;
}
if(i%(5*5*5)==0){
cnt1++;
}
if(i%(5*5*5*5)==0){
cnt1++;
}
if(i%(5*5*5*5*5)==0){
cnt1++;
}
if(i%(5*5*5*5*5*5)==0){
cnt1++;
}
if(i%(5*5*5*5*5*5*5)==0){
cnt1++;
}
if(i%(5*5*5*5*5*5*5*5)==0){
cnt1++;
}
}
for(int i=mother;i>=1;i--){
if(i%5==0){
cnt2++;
}
if(i%(5*5)==0){
cnt2++;
}
if(i%(5*5*5)==0){
cnt2++;
}
if(i%(5*5*5*5)==0){
cnt2++;
}
if(i%(5*5*5*5*5)==0){
cnt2++;
}
if(i%(5*5*5*5*5*5)==0){
cnt2++;
}
if(i%(5*5*5*5*5*5*5)==0){
cnt2++;
}
if(i%(5*5*5*5*5*5*5*5)==0){
cnt2++;
}
}
printf("%d",cnt1-cnt2);
return 0;
}