Advertisement
Goga21

Untitled

Mar 28th, 2024
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.00 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 + 1 == c){
  31.                 if(b == 1){
  32.                     cout << a << '\n';
  33.                 }else {
  34.                     int h = 1, floor = 1, p = 0;
  35.                     if(a % 2 == 0){
  36.                         p = 1;
  37.                     }
  38.                     while (true) {
  39.                         if (a - floor >= 0) {
  40.                             a -= floor;
  41.                             floor *= 2;
  42.                             h++;
  43.                         } else {
  44.                             break;
  45.                         }
  46.                     }
  47.                     b = b - (floor - a);
  48.                     if(p == 1){
  49.                         while (true) {
  50.                             b = b - floor - 1;
  51.                             h++;
  52.                             if (b <= 0) {
  53.                                 break;
  54.                             }
  55.                         }
  56.                     }else{
  57.                         while (true) {
  58.                             b -= floor;
  59.                             h++;
  60.                             if (b < 0) {
  61.                                 break;
  62.                             }
  63.                         }
  64.                     }
  65.                     cout << h << '\n';
  66.                 }
  67.             }else{
  68.                 cout << -1 << '\n';
  69.             }
  70.         }
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement