/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 532.0 KiB
#2 Wrong Answer 1ms 532.0 KiB
#3 Accepted 1ms 532.0 KiB
#4 Accepted 32ms 832.0 KiB
#5 Wrong Answer 33ms 844.0 KiB

Code

#include <bits/stdc++.h>
using namespace std;

#define ll long long int
#define ld long double
#define endl '\n'
#define fasterio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define yes cout << "YES" << endl
#define no cout << "NO" << endl

// void solve() {
//     // Your code here
//     ll a,b;
//     cin>>a>>b;
//     ll count=0;
//     while (a!=b)
//     {
//         if(b%2==0){
//             b/=2;
//             count++;
//         }else{
//             b--;
//             count++;
//         }
//     }
//     cout<<count<<endl;
    
// }
void solve() {
    ll a,b;
    cin>>a>>b;
    ll count=0;
    while (b>a) {
        if(b%2==0) {
            b/=2;
        }else{
            b--;
        }
        count++;
    }
    // count+=a-b;
    // cout<<count<<endl;
    if(a==b){
        cout<<count<<endl;
    }else{
        ll d=abs(a-b);
        cout<<count+d<<endl;
    }
}

int main() {
    fasterio;
    // Always use ll, int may give TLE
    ll t;
    cin >> t;
    // t=1;
    while (t--) {
        solve();
    }
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1044 Add or multiple
Contest
TLE_Headquarters - round #1
Language
C++20 (G++ 13.2.0)
Submit At
2024-03-27 17:01:05
Judged At
2024-11-11 03:37:49
Judged By
Score
60
Total Time
33ms
Peak Memory
844.0 KiB