InterviewBit Academy is now Scaler!
Learn Tech Skills from Scratch @ Scaler EDGE

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
Sign Up
to access hints and editorial solutions for Largest Coprime Divisor


Click here to start solving coding interview questions