-
1676) 팩토리얼 0의 개수 - JAVA백준코딩일기 2020. 1. 15. 15:02
https://www.acmicpc.net/problem/1676
12345678910111213141516171819202122public class Main {public static void main(String[] args) throws IOException{BufferedReader br = new BufferedReader(new InputStreamReader(System.in));BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));// 입력받을 수 => N!long N = Integer.parseInt(br.readLine());// 0의 갯수를 담을 변수int cnt=0;// 뒤에서부터 나오는 0의 갯수를 찾으려면 전체 펙토리얼(!)에 5가 몇번 나오는지 확인하면 됨// 그래서 index는 5부터 시작하고 N과 같거나 작을 때까지 확인// 25 50 75... 처럼 5가 2개씩 들어가는 경우가 있음// 그래서 index가 n보다 작거나 같을 동안에는// index를 5의 배수로 증가시키면서// N을 index로 나눈 값을 변수에 담아준다.for(int index = 5; index<=N; index*=5) {cnt += N/index;}}} cs'백준코딩일기' 카테고리의 다른 글
2004) 조합 0의 개수 - Java (0) 2020.01.15 10872) 팩토리얼 - JAVA (0) 2020.01.15 1158) 조세푸스 문제 - JAVA (0) 2020.01.06 2741) N 찍기 - JAVA (0) 2020.01.01 10814) 나이순 정렬 - JAVA (0) 2019.12.29