# 孔融不让梨

``````3
8 14
219 111
210 35``````

``````4/7
73/37
6/1
``````

``````#include <stdio.h>
#include <stdlib.h>
int main()
{
int n,a,b,i,j;
scanf("%d",&n);
while(n--)
{
scanf("%d%d",&a,&b);
for(i=a;i>0;i--)
if (a%i==0&&b%i==0)
break;
a=a/i;
b=b/i;
printf("%d/%d\n",a,b);
}
return 0;
}``````

``````#include <iostream>

using namespace std;
class Fraction
{ private:
int numerator;    //分子
int denominator;  //分母
int gcd(int , int );

public:
Fraction(int=0 , int=1);
void Simplify();  //约分
void SetFraction(int , int);
friend ostream& operator<<(ostream&,Fraction&);   //输出分式
};
int Fraction::gcd(int m,int n){
int r;   if (m<n) {r=m ; m=n ; n=r; }
while((r=m%n)!=0)
{    m=n;   n=r;    }
return n;
}
Fraction::Fraction(int nume,int deno)
{
numerator=nume; denominator=deno;
}
void Fraction::SetFraction(int nume,int deno)
{
numerator=nume; denominator=deno;
}
void Fraction::Simplify()
{
int num=gcd(numerator,denominator);
numerator/=num;
denominator/=num;
}
ostream& operator<<(ostream& output,Fraction& f){
cout<<f.numerator<<"/"<<f.denominator;
return output;
}
int main()
{
Fraction f;
short int n,i;
int nume,deno;
cin>>n;
for(i=0;i<n;i++)
{
cin>>nume>>deno;
f.SetFraction(nume,deno);
f.Simplify();
cout<<f<<endl;
}
return 0;
}``````