Monday 22 January 2018

gcd and lcm - The maximum valued integer X such that X divides A i.e. A % X = O and X and B are co-prime

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

real analysis - How to find $lim_{hrightarrow 0}frac{sin(ha)}{h}$

How to find $\lim_{h\rightarrow 0}\frac{\sin(ha)}{h}$ without lhopital rule? I know when I use lhopital I easy get $$ \lim_{h\rightarrow 0}...