/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Wrong Answer 15ms 3.0 MiB
#2 Wrong Answer 15ms 3.113 MiB

Code

# Function to find minimum operations to make A equal to B
def min_operations(A, B):
    # If A is already equal to B, no operations needed
    if A == B:
        return 0

    # If A is greater than B, return -1 indicating impossible
    if A > B:
        return -1

    # Initialize count of operations
    operations = 0

    # Continue until A becomes equal to or greater than B
    while A < B:
        # If B is odd, subtract 1 from B
        if B % 2 == 1:
            B -= 1
        # Otherwise, if B is even, divide B by 2
        else:
            B //= 2
        # Increment the count of operations
        operations += 1

    return operations

# Number of test cases
T = int(input("Enter the number of test cases: "))

# Iterate through each test case
for _ in range(T):
    A, B = map(int, input().split())
    print(min_operations(A, B))

Information

Submit By
Type
Submission
Problem
P1044 Add or multiple
Contest
TLE_Headquarters - round #1
Language
Python 3 (Python 3.12.3)
Submit At
2024-03-27 16:18:15
Judged At
2024-11-11 03:39:07
Judged By
Score
0
Total Time
15ms
Peak Memory
3.113 MiB