File tree Expand file tree Collapse file tree
백준/Silver/1676. 팩토리얼 0의 개수 Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments