https://www.acmicpc.net/problem/10166
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.StringTokenizer;
public class java_10166 {
static int euclid(int a, int b) {
while (b != 0) {
int tmp = a;
a = b;
b = tmp % b;
}
return a;
}
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer st = new StringTokenizer(br.readLine());
int D1 = Integer.parseInt(st.nextToken());
int D2 = Integer.parseInt(st.nextToken());
int result = 0;
boolean map[][] = new boolean[D2 + 1][D2 + 1];
for (int i = D1; i < D2 + 1; i++) {
for (int j = 1; j <= i; j++) {
// 최소 공배수
int gcd = euclid(i, j);
// 분모
int a = (int) j / gcd;
// 분자
int b = (int) i / gcd;
if (!map[a][b]) {
map[a][b] = true;
result++;
}
}
}
bw.write(result + "\n");
br.close();
bw.close();
}
}
'Coding Test > BOJ' 카테고리의 다른 글
[BOJ/JAVA] 1016번: 제곱 ㄴㄴ 수 (0) | 2022.08.23 |
---|---|
[BOJ/JAVA] 2981번: 검문 (0) | 2022.08.21 |
[BOJ/JAVA] 2485번: 가로수 (0) | 2022.08.21 |
[BOJ/JAVA] 9935번: 문자열 폭발 (0) | 2022.08.21 |
[BOJ/JAVA] 5052번: 전화번호 목록 (0) | 2022.08.21 |