UVA – 10814 – Simplifying Fractions

import java.io.IOException;
import java.math.BigInteger;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws IOException {
		 Scanner in = new Scanner(System.in);
		 int r = Integer.parseInt(in.nextLine());
			while (r--!=0) {
				String[] big = in.nextLine().split(" ");
			BigInteger a = new BigInteger(big[0]);
			BigInteger b = new BigInteger(big[2]);
			BigInteger gcd = a.gcd(b);
			a = a.divide(gcd);
			b = b.divide(gcd);
			System.out.println(a+ " / "+ b);
		}
	}
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: