Advertisement
gha890826

ACM ICPC TAIWAN 2016[Problem A] Every Runner is Sometimes Lo

Sep 14th, 2018
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3. #include<cmath>
  4. #include<cstdlib>
  5. #include<fstream>
  6. #include <vector>
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11.     int c,v1,v2;
  12.     while(cin>>c)
  13.     {
  14.         if(c!=0)
  15.         {
  16.             cin>>v1>>v2;
  17.             int dif=v2-v1;
  18.             if(dif<0)
  19.                 dif*=-1;
  20.             dif*=2;
  21.             if(dif==0)
  22.             {
  23.                 printf("false\n");
  24.             }
  25.             else if(c%dif==0)
  26.             {
  27.                 cout<<c/dif*v1<<endl;
  28.             }
  29.             else
  30.             {
  31.                 int x=c,y=dif;
  32.                 int tmp;
  33.                 while (x % y != 0)
  34.                 {
  35.                     tmp = y;
  36.                     y = x % y;
  37.                     x = tmp;
  38.                 }
  39.                 cout<<c*v1/y<<"/"<<dif/y<<endl;
  40.             }
  41.         }
  42.         else
  43.             break;
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement