分数加减乘除模板 

#include<cstdio>
#include<cmath>
#include<iostream>
using namespace std;

typedef long long ll;
struct Fraction{
	ll up,down;
};

int gcd(int a,int b){
	return b==0? a: gcd(b,a%b);
} 


Fraction reduction(Fraction a){
	if (a.down < 0){
		a.up = -a.up;
		a.down = -a.down;
	}
	
	if(a.up == 0){
		a.down = 1;
	}else{
		ll d = gcd(abs(a.down),abs(a.up));

		a.up /=d;
		a.down /=d;
	}
	
	return a;
}

Fraction add(Fraction a, Fraction b){
	
	Fraction result;
	result.down = a.down*b.down;
	result.up = a.up*b.down + b.up*a.down;
	return reduction(result);
}



Fraction sub(Fraction a, Fraction b){
	
	Fraction result;
	result.down = a.down*b.down;
	result.up = a.up*b.down - b.up*a.down;
	return reduction(result);
}

Fraction mul(Fraction a, Fraction b){
	
	Fraction result;
	result.down = a.down*b.down;
	result.up = a.up*b.up;
	return reduction(result);
}

Fraction div(Fraction a, Fraction b){
	
	Fraction result;
	result.down = a.down*b.up;
	result.up = a.up*b.down;
	return reduction(result);
}


void reustPrint(Fraction a){
	if(a.down == 1) {
		printf("%d\n",a.up);return;
	}
	
	if(abs(a.up) > a.down){
		printf("%d %d/%d\n",a.up/a.down,a.up%a.down,a.down);
		return;
	}
		
	printf("%d/%d\n",a.up,a.down);
	return;
}

int main(){
	
	ll a,b,c,d;
	scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
	Fraction num1,num2;
	num1.up = a;
	num1.down = b;
		
	num2.up = c;
	num2.down = d;
	
	
	Fraction add_ = add(num1,num2);
	printf("add:\n");
	reustPrint(add_);
	Fraction sub_ = sub(num1,num2);
	printf("sub:\n");
	reustPrint(sub_);
	
	Fraction mul_ = mul(num1,num2);
	printf("mul:\n");
	reustPrint(mul_);
	
	Fraction div_ = div(num1,num2);
	printf("div:\n");
	reustPrint(div_);
	
	return 0;
}