Participate in Codex, Test Your Skills & Win BIG

Largest Coprime Divisor

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

For example,

A = 30
B = 12
We return
X = 5
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving Largest Coprime Divisor on Interview Code Editor
Hints
  • Hint 1
  • Solution Approach
  • Complete Solution

Discussion


Loading...
Click here to start solving coding interview questions