### Akshansh_01's blog

By Akshansh_01, history, 2 months ago,

Help me with this one!!! Whatever the logic I'm applying, time limit gets exceeded in the Test Case 4. This is my solution — https://codeforces.com/contest/1328/submission/167650940 I've tried without storing the values and directly printing it but the result was same — Time Limit Exceeded.

• 0

 » 2 months ago, # | ← Rev. 2 →   0 It's pretty easy: we have an integer a and we want to find out which another minimal integer we must add to a such that (a + x) % b == 0. let's look at a % b — if it equals to 0, we must add nothing, so just output 0. Else, we just add (b — a % b) and we're done. 167658837
 » 2 months ago, # | ← Rev. 2 →   0 It looks like you're trying to brute force add $1$ to $a$ until it becomes divisible by $b$, which looking at TC4 would definitely time out if the required amount to add is significantly large. There's an easy $\mathcal O(1)$ solution for each pair of numbers in a given test case, which involves a slight bit of number theory. HintTry to think about what how much you have to add, relative to the remainder from dividing the original numbers.167658597
 » 2 months ago, # |   0 Read the Tutorial: we just need to print b — b%a because we always increase b
 » 2 months ago, # |   0 Thanks for helping out!!!