Guest User

Untitled

a guest
Feb 6th, 2017
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. //in the name of allah
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4. typedef long long ll;
  5.  
  6. int main(){
  7.         ios_base::sync_with_stdio(false);cin.tie(NULL);
  8.         int q;cin >> q;
  9.         ll MX = 1e18;
  10.         while(q--){
  11.                 ll a , b;cin >> a >> b;
  12.                 ll g = __gcd(a , b);
  13.                 a /= g;
  14.                 b /= g;
  15.                 ll ans=0;
  16.                 while(a && b){
  17.                         if(a<b) swap(a , b);
  18.                         ans += a/b;
  19.                         a %= b;
  20.                 }
  21.                 cout << ans-1 << "\n";
  22.         }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment