it/알고리즘
백준 1735 - 분수 합
하얀나다
2019. 12. 17. 23:13
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
/*
2 7
3 5
*/
import java.io.FileInputStream;
public class Main {
static int a1,a2,b1,b2;
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
a1 = sc.nextInt();
a2 = sc.nextInt();
b1 = sc.nextInt();
b2 = sc.nextInt();
int a = (a1*b2) + (b1 * a2);
int b = a2 * b2;
int c = div(a,b);
int x = a/c;
int y = b/c;
System.out.println(x + " " + y);
}
private static int div(int a, int b) {
while(b != 0) {
int x = a%b;
a = b;
b = x;
}
return a;
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|