#include <stdio.h>

#include "reduce.h"
#include "utils.h"

int subFrac(int x[], int y[]) {
    if (x[1] == 0 || y[1] == 0) {
        return -1;
    }

    int l = lcm(x[1], y[1]);
    int z[] = {
        (x[0] * l)/x[1] - (y[0] * l)/y[1],
        l
    };

    reduce(z);
    formatNeg(z);

    x[0] = z[0];
    x[1] = z[1];

    return 0;
}

int main(void) {
    int x[2] = {0};
    int y[2] = {0};

    inputFrac(x);
    inputFrac(y);

    int ret = subFrac(x, y);

    if (ret == 0) {
        printFrac(x);
        putchar('\n');
    } else {
        fprintf(stderr, "Error: detected zero div\n");
    }

    return 0;
}
