Please, try EDU on Codeforces! New educational section with videos, subtitles, texts, and problems. ×

ankit_18's blog

By ankit_18, history, 9 days ago, In English,

Your text to link here...Anyone solved this one??

 
 
 
 
  • Vote: I like it
  • -10
  • Vote: I do not like it

»
9 days ago, # |
  Vote: I like it 0 Vote: I do not like it

...which one?

»
9 days ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by ankit_18 (previous revision, new revision, compare).

»
9 days ago, # |
Rev. 2   Vote: I like it +3 Vote: I do not like it

You can solve that problem using the Chinese Remainder Theorem. You want to find the first time they collide x where:

  • x = n % m
  • x = k % a

Once you have this x, you can add the LCM of m and a to x until it is >= max(n, k). (you can math the second part out to solve it in O(1), plus CRT stuff)

  • »
    »
    9 days ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    Thanks Can u explain it more in psuedo code format please??

    • »
      »
      »
      9 days ago, # ^ |
      Rev. 2   Vote: I like it +3 Vote: I do not like it

      No man, I'm not going to write out psuedocode that solves the Chinese remainder theorem for you after I just gave you a link to learn it if you won't even fix the link on your question.

      Here is a good youtube tutorial which helped me learn it, if you struggle reading through the Wikipedia article.

      If what I wrote still doesn't make sense after you understand CRT, then this is probably a little bit too difficult of a problem for you to be solving at the moment. It might be more helpful to practice on easier problems until you are a bit more comfortable on implementation and then come back to this in a few weeks or so.

      • »
        »
        »
        »
        9 days ago, # ^ |
          Vote: I like it +10 Vote: I do not like it

        Yes you r ri8..I should solve the easier problem first btw thanks for ur time