/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 340.0 KiB
#2 Wrong Answer 1ms 328.0 KiB
#3 Accepted 1ms 516.0 KiB
#4 Accepted 62ms 580.0 KiB
#5 Wrong Answer 64ms 696.0 KiB

Code

#include <stdio.h>

// Function to find minimum operations to make A equal to B
int minOperations(int A, int 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;

    // If B is odd, subtract 1 from B and recursively call the function
    // If B is even, divide B by 2 and recursively call the function
    if (B % 2 == 0)
        return 1 + minOperations(A, B / 2);
    else
        return 1 + minOperations(A, B - 1);
}

int main() {
    int T;
    scanf("%d", &T);

    while (T--) {
        int A, B;
        scanf("%d %d", &A, &B);
        printf("%d\n", minOperations(A, B));
    }

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1044 Add or multiple
Contest
TLE_Headquarters - round #1
Language
C99 (GCC 13.2.0)
Submit At
2024-03-27 16:16:12
Judged At
2024-11-11 03:39:13
Judged By
Score
60
Total Time
64ms
Peak Memory
696.0 KiB