Problem: https://www.codechef.com/LRNDSA01/problems/MULTHREE

Solution: https://ide.geeksforgeeks.org/Mvqc0RD70y

The 3rd case: `760399384224 5 1`

gives status: time limit exceeded

Problem: https://www.codechef.com/LRNDSA01/problems/MULTHREE

Solution: https://ide.geeksforgeeks.org/Mvqc0RD70y

The 3rd case: `760399384224 5 1`

gives status: time limit exceeded

You can use a simple trick to optimise your code.

Notice that after 4 or 5 numbers you end up in wither of the two cycles {2, 4, 8, 6} or {0}.

For {0}: Just check the sum of the first three digits and you are done!

For the other case: You can first check from where the cycle starts, see how many times the cycle is repeated and multiply that by 20 (2 + 4 + 6 + 8). And add the residual non - repeating bits.

@archisha I’m trying to figure it out myself. I’m not sure if you’re still working on it, but the algorithm you have for it is incorrect. if you take out the 3rd test case, it runs fast enough to compute and it gives the incorrect answer. I’m trying my absolute best to simplify it, but even with as minimal math as i can, it’s still TLE.