728x90
문제
내 풀이
import java.util.Scanner;
public class LCM2 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int A = scanner.nextInt();
int B = scanner.nextInt();
int C = scanner.nextInt();
int D = scanner.nextInt();
int numerator = A * D + B * C;
int denominator = B * D;
int gcd = gcd(numerator, denominator);
System.out.println((numerator / gcd) + " " + (denominator / gcd));
}
public static int gcd(int a, int b) {
while (b != 0) {
int temp = b;
b = a % b;
a = temp;
}
return a;
}
}
728x90
'백준' 카테고리의 다른 글
백준 4134 - Java (0) | 2024.09.03 |
---|---|
백준 2485 - Java (0) | 2024.09.02 |
백준 13241 - Java (0) | 2024.09.02 |
백준 1934 - java (0) | 2024.09.02 |
백준 11478 - Java (0) | 2024.09.02 |