https://www.acmicpc.net/problem/2004
코드 :
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int N = Integer.parseInt(st.nextToken());
int M = Integer.parseInt(st.nextToken());
int five = fivePowCount(N) - fivePowCount(N - M) - fivePowCount(M);
int two = twoPowCount(N) - twoPowCount(N - M) - twoPowCount(M);
System.out.println(Math.min(five,two));
}
public static int fivePowCount(int num) {
int fiveCount = 0;
while (num >= 5) {
fiveCount += num/ 5;
num /= 5;
}
return fiveCount;
}
public static int twoPowCount(int num) {
int twoCount = 0;
while (num >= 2) {
twoCount += num/ 2;
num /= 2;
}
return twoCount;
}
}
참고 :
'알고리즘 > 백준' 카테고리의 다른 글
백준 17087번 - 숨바꼭질 6 (Java 8) (0) | 2022.03.16 |
---|---|
백준 9613번 - GCD합 (Java 8) (0) | 2022.03.16 |
백준 1676번 - 팩토리얼 0의 개수 (Java 8) (0) | 2022.03.15 |
백준 6588번 - 골드바흐의 추측 (Java 8) (0) | 2022.03.15 |
백준 1934번 - 최소공배수 (Java 8) (0) | 2022.03.15 |
댓글