Skip to content

Commit 66b997d

Browse files
committed
[Silver V] Title: 팩토리얼 0의 개수, Time: 112 ms, Memory: 14720 KB -BaekjoonHub
1 parent 554c1a7 commit 66b997d

2 files changed

Lines changed: 70 additions & 0 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# [Silver V] 팩토리얼 0의 개수 - 1676
2+
3+
[문제 링크](https://www.acmicpc.net/problem/1676)
4+
5+
### 성능 요약
6+
7+
메모리: 14720 KB, 시간: 112 ms
8+
9+
### 분류
10+
11+
수학
12+
13+
### 제출 일자
14+
15+
2025년 2월 28일 00:20:10
16+
17+
### 문제 설명
18+
19+
<p>N!에서 뒤에서부터 처음 0이 아닌 숫자가 나올 때까지 0의 개수를 구하는 프로그램을 작성하시오.</p>
20+
21+
### 입력
22+
23+
<p>첫째 줄에 N이 주어진다. (0 ≤ N ≤ 500)</p>
24+
25+
### 출력
26+
27+
<p>첫째 줄에 구한 0의 개수를 출력한다.</p>
28+
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import java.math.BigInteger;
2+
import java.util.*;
3+
import java.io.*;
4+
5+
public class Main {
6+
// static Long sum;
7+
static int N, cnt;
8+
9+
public static void main(String[] args) throws IOException{
10+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
11+
12+
N = Integer.parseInt(br.readLine());
13+
14+
// sum=1L;
15+
16+
BigInteger factorial = BigInteger.ONE;
17+
18+
for(int i=1; i<=N; i++){
19+
factorial = factorial.multiply(BigInteger.valueOf(i));
20+
// sum *= i;
21+
}
22+
23+
String s = factorial.toString();
24+
25+
// String s = Long.toString(sum);
26+
cnt=0;
27+
28+
29+
// System.out.println(s);
30+
for(int i=s.length()-1; i>0; i--){
31+
if(s.charAt(i) == '0'){
32+
cnt++;
33+
}
34+
35+
if(s.charAt(i-1) != '0'){
36+
break;
37+
}
38+
}
39+
40+
System.out.println(cnt);
41+
}
42+
}

0 commit comments

Comments
 (0)