print ‘Yes’ if (a**18)%b==0 else ‘No’
^This works too. Maybe the test cases are weak.
Yes! we need to think a problem in a logical fashion. Applying some basic math can solve this problem. We should write code but not scrap
Hi can body please tell me what wrong with my code because it’s not accepted fully. I just implemented the editorial this is link to my solution
In @hippie’s solution, I’ll elaborate a bit on what @mrho888 said.
Lets assume A = p1^a1 * p2^a2 … * pk^ak and B = q1^b1 * q2^b2 … qm^bm
To solve the problem, we need to see whether the set {q1…qm} is a subset of {p1…pk}. Now consider A^x: clearly if there exists any x such that A^x is not divisible by B, we can say that there is some prime in B that is not there in A and the answer to the problem is “NO”. Also, we can see that B divides A^x if and only if B contains all the prime divisors of A. Now all that remains is to find a big enough x such that B divides A^x. Now the largest necessary “x” occurs when A = p, B = p^x. Since A,B <= 10^18, with p = 2, we get the largest neccesary x as ceil(log2(10^18)) which is around 60.
PS: This was an amazing approach, kudos @hippie
i claculated gcd until it came out to be one, in each step divide B by gcd and after that if B==1 print yes else no.
@ ambarpal
I cant understand this
the largest necessary “x” occurs when A = p, B = p^x. Since A,B <= 10^18, with p = 2, we get the largest neccesary x as ceil(log2(10^18)) which is around 60.
can u explain this??
http://www.codechef.com/submit/complete/618032-10171--556ad41f12d55
can someone help me with the reason of tle in above code…
I am getting Run time error all the time.Someone help me out.This is my solution
https://www.codechef.com/viewsolution/19190554