Help me in solving BMCCP15A problem

My issue


Receiving mentioned error as “Time Limit Exceeded”, although the output is as per the requirements. I’m not sure why this issue is there.

My code

// Update the code below to solve this problem

#include <stdio.h>
#include <stdlib.h>

int main() 
{
    int t;
    scanf("%d", &t);
    while (t--) 
    {
        int N, M;
        scanf("%d %d", &N, &M);
        int count = 0;
        for (int i = 1; i<= (N<M ? N:M); i++)
        {
            if ((N%i == 0) && (M%i == 0))
            {
                count = i;
            }
        }
        printf("%d \n", count);
    }
    
    return 0;
}

Learning course: C for problem solving - 2
Problem Link: CodeChef: Practical coding for everyone

@mk1910
the constraints of n and m are very big u can’t loop it to find gcd
there is also a way to find gcd in log(n) time complexity just google it u will find the relevant articles.

1 Like

Thanks for your suggestion.