I came across this question while practicing coding questions -
You are given two positive numbers A and B. You need to find the maximum valued integer X such that:
X divides A i.e. A % X = 0
X and B are co-prime i.e. gcd(X, B) = 1
I could only think of a brute force approach where I check for all the factors of A and test if that is coprime with B. Is there any faster way to do this?
No comments:
Post a Comment