Advertisement
Goga21

Untitled

Mar 28th, 2024
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.41 KB | Source Code | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. #define int long long
  4.  
  5. using namespace std;
  6.  
  7. signed main(){
  8.     int t;
  9.     cin >> t;
  10.     while(t--) {
  11.         int a, b, c;
  12.         cin >> a >> b >> c;
  13.         if(c == 0){
  14.             cout << -1 << '\n';
  15.         }else if(a == 0){
  16.             if(b == 0 && c == 1){
  17.                 cout << 0 << '\n';
  18.             }else if(b > 0 && c == 1){
  19.                 cout << b << '\n';
  20.             }else{
  21.                 cout << -1 << '\n';
  22.             }
  23.         }else if(b == 0){
  24.             if(a + 1 == c){
  25.                 cout << a << '\n';
  26.             }else{
  27.                 cout << -1 << '\n';
  28.             }
  29.         }else{
  30.             if(a + b == c){
  31.                 cout << a << '\n';
  32.             }else if(a + 1 == c){
  33.                 int h = 1, floor = 1;
  34.                 while(true){
  35.                     if(a - floor > 0){
  36.                         a -= floor;
  37.                         floor *= 2;
  38.                         h++;
  39.                     }else{
  40.                         break;
  41.                     }
  42.                 }
  43.                 b = b - (floor - a);
  44.                 while(true){
  45.                     b -= floor;
  46.                     h++;
  47.                     if(b < 0){
  48.                         break;
  49.                     }
  50.                 }
  51.                 cout << h<< '\n';
  52.             }else{
  53.                 cout << -1 << '\n';
  54.             }
  55.         }
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement