View Code of Problem 66

#include <iostream>
#include <algorithm>

using namespace std;

int yue(int x,int y){
    for(int i=2;i<=min(x,y);i++){
        if(x%i==0&&y%i==0)return i;
    }
    return 1;

}

int main(){

    int a,b;
    while (cin>>a>>b)
    {
        if(a==b)cout<<1<<endl;
        else{
            while(yue(a,b)!=1){
                int c=yue(a,b);
                a=a/c;
                // cout<<a<<endl;
                b=b/c;
                //  cout<<b<<endl;
            }
                cout<<a<<"/"<<b<<endl;
            }


        

    }
    


    return 0;
}

Double click to view unformatted code.


Back to problem 66