Java Reduce a fraction
Very easy
Execution time limit is 1 second
Runtime memory usage limit is 128 megabytes
Reduce a fraction to the lowest terms.
Implement a class Fraction that uses a wrapper class MyLong.
class MyLong // Java {` private long a; // one private variable MyLong(long a) // Constructor public String toString() // Print a variable of type MyLong public MyLong Abs() // return the absolute value of variable of type MyLong public long GetValue() // return the value of private variable of type long private static long gcd(long a, long b) // find the GCD of two variables of type long public static MyLong gcd(MyLong a, MyLong b) // find the GCD of two variables of type MyLong public MyLong Divide(MyLong a) // divide two numbers }; class Fraction { MyLong numerator, denominator; // numerator and denominator Fraction() // Constructor Fraction (MyLong numerator, MyLong denominator) // Constructor public String toString() // Print a variable of type Fraction public Fraction Reduce() // Reduce a Fraction };
Input
Two integers a and b (-10^18
≤ a, b ≤ 10^18
).
Output
Print the reduced fraction in the form a / b.
Examples
Input #1
Answer #1
Submissions 308
Acceptance rate 40%