백준 1676

hong030·2023년 2월 24일
0
  • 실버 5단계 문제

풀이)
입력으로 500까지도 들어갈 수 있기 때문에 단순히 팩토리알을 모두 계산해 수를 구하면 시간 초과가 난다. (500!가 너무 크기 때문.)
때문에 5와 2가 곱해진 횟수를 구하면 답을 알 수 있다.

내 코드)

import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
 
		int num = in.nextInt();
		int count = 0;
 
		while (num >= 5) {
			count += num / 5;
			num /= 5;
		}
		System.out.println(count);
	}
 
}

profile
자바 주력, 프론트 공부 중인 초보 개발자. / https://github.com/hongjaewonP

0개의 댓글