using System;
namespace Answer {
internal static class Solution {
static void Main() {
var frac1 = new Fraction(3, 5);
var frac2 = new Fraction(15, 16);
var frac3 = frac1.Multiplication(frac2);
Console.WriteLine(frac3);
Console.ReadKey();
}
}
internal class Fraction(long numerator, long denominator) {
public long Numerator { get; set; } = numerator;
public long Denominator { get; set; } = denominator;
public void ReduceAFraction() {
if (Denominator != 0) {
var gcd = Gcd();
Denominator /= gcd;
Numerator /= gcd;
}
}
private long Gcd() {
long num = Numerator;
long den = Denominator;
long remainder;
while (den != 0) {
remainder = num % den;
num = den;
den = remainder;
}
return num;
}
public override string ToString() {
ReduceAFraction();
return $"{Numerator}/{Denominator}";
}
public Fraction Multiplication(Fraction other) {
return new Fraction(Numerator * other.Numerator, Denominator * other.Denominator);
}
}
}
using System;
namespace Answer {
internal static class Solution {
static void Main() {
var frac1 = new Fraction(3, 5);
var frac2 = new Fraction(15, 16);
var frac3 = frac1 * frac2;
Console.WriteLine(frac3);
Console.ReadKey();
}
}
internal class Fraction {
public long Numerator { get; set; }
public long Denominator { get; set; }
public Fraction(long numerator, long denominator) {
Numerator = numerator;
Denominator = denominator;
ReduceAFraction();
}
public static Fraction operator*(Fraction a, Fraction b) {
var frac = new Fraction(a.Numerator * b.Numerator, a.Denominator * b.Denominator);
frac.ReduceAFraction();
return frac;
}
private void ReduceAFraction() {
if (Denominator != 0) {
var gcd = Gcd();
Denominator /= gcd;
Numerator /= gcd;
}
}
private long Gcd() {
var num = Numerator;
var den = Denominator;
long remainder;
while (den != 0) {
remainder = num % den;
num = den;
den = remainder;
}
return num;
}
public override string ToString() {
return $"{Numerator}/{Denominator}";
}
}
}