Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- class Task1_5_1 {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int m = 0, n = 0, gcd;
- int a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt(), d = sc.nextInt();
- m = (a * d) + (c * b);
- n = b * d;
- gcd = GCD(m, n);
- m /= gcd;
- n /= gcd;
- System.out.println(m + " " + n);
- }
- public static int GCD(int a, int b) {
- if (b == 0)
- return a;
- else return GCD(b, a % b);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment