#include #include typedef long long longnum; // greatest common divisor longnum gcd(longnum a, longnum b) { while ( b > 0 ) { longnum t = b; b = a % b; a = t; } return a; } void simplify(longnum* num, longnum* den) { longnum common = gcd(*num, *den); *num = *num / common; *den /= common; } int main(int argc, char* argv[]) { if ( argc <= 2 ) return printf("usage: simplify a b\n"); longnum num = atoll(argv[1]); longnum den = atoll(argv[2]); printf("%lli/%lli = ", num, den); simplify(&num, &den); printf("%lli/%lli\n", num, den); return 0; }