Advertisement
Guest User

Untitled

a guest
Jun 8th, 2014
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3.  
  4. using namespace std;
  5. unsigned int hcf(unsigned long a, unsigned long b) {
  6.    if (b == 0) {
  7.       return a;
  8.    } else {
  9.       return hcf(b, a % b);
  10.    }
  11. }
  12. int main()
  13. {
  14. //  freopen("out.txt","w",stdout);
  15. //  freopen("in.txt","r",stdin);
  16.     unsigned long  T,N[100000],M[100000],i,j,no,ne,mo,me,n1,n2,k;
  17.     cin>>T;
  18.     for(i=0;i<T;i++) cin>>N[i]>>M[i];
  19.     for(i=0;i<T;i++)
  20.     {
  21.         no = ne = N[i]/2;
  22.         if(N[i]%2!=0) no++;
  23.         mo = me = M[i]/2;
  24.         if(M[i]%2!=0) mo++;
  25.         n1 = ne*mo + no*me;
  26.         n2 = N[i]*M[i];
  27.         do
  28.         {
  29.             k = hcf(n1,n2);
  30.             n1/=k;
  31.             n2/=k;
  32.         }while(k!=1);
  33.         cout<<n1<<"/"<<n2<<endl;
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement