fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int t,p,q;
  5. long long dequy(int p,int q){
  6. if (p==q) return 0;
  7. if (p>q) return 2*dequy(p-q,q)+2;
  8. return 2*dequy(p,q-p)+1;
  9. }
  10.  
  11. int main(){
  12. ios_base::sync_with_stdio(false);
  13. cin.tie(NULL);
  14. cin >> t;
  15. while(t--){
  16. cin >> p >> q;
  17. cout << dequy(p,q) << "\n";
  18. }
  19. }
  20.  
Success #stdin #stdout 0s 5276KB
stdin
Standard input is empty
stdout
Standard output is empty