문제
N!에서 뒤에서부터 처음 0이 아닌 숫자가 나올 때까지 0의 개수를 구하는 프로그램을 작성하시오.
입력
첫째 줄에 N이 주어진다. (0 ≤ N ≤ 500)
출력
첫째 줄에 구한 0의 개수를 출력한다.
예제 입력 1
10 |
예제 출력 1
2 |
더보기
Solution
#include<stdio.h>
int divideby2(int N)
{
int count=0;
while(N%2==0)
{
count++;
N/=2;
}
return count;
}
int divideby5(int N)
{
int count=0;
while(N%5==0)
{
count++;
N/=5;
}
return count;
}
int main(void)
{
int N, two=0, five=0;
scanf("%d", &N);
for(int i=2;i<=N;i++)
{
two+=divideby2(i);
five+=divideby5(i);
}
printf("%d\n", two<five?two:five);
return 0;
}
728x90
'백준 알고리즘' 카테고리의 다른 글
<백준 알고리즘> 5597번: 과제 안 내신 분..? (0) | 2020.07.17 |
---|---|
<백준 알고리즘> 2522번: 별 찍기 - 12 (0) | 2020.07.17 |
<백준 알고리즘> 15680번: 연세대학교 (0) | 2020.07.17 |
<백준 알고리즘> 1065번: 한수 (0) | 2020.07.16 |
<백준 알고리즘> 2920번: 음계 (0) | 2020.07.16 |