What's wrong with this Code?

Problem Statement: https://www.codechef.com/FFC12019/problems/SHADOW

Solution: https://www.codechef.com/viewsolution/24887571

One quick thing to check should be the case when L > R. They have mentioned it, in bold, that it is not necessary that L <= R or vice versa. So, basically what you need to do is, if L>R, swap L and R.

But still, I would say it was ambiguous what to do with it if L > R. Since statement said " values between L to R (inclusive) ", I thought, if L>R, then there are no values from L to R. So, I considered PS=0 and Sum of values divisible by LCM(A,B) also to be 0. But it didn’t work, so I thought, let’s try with swapping L and R, and it worked. All in all, it was not a good problem statement. It could and should have been more clear.

Damn! missed that condition…
Got AC now https://www.codechef.com/viewsolution/24889225

BTW Thanks!

No problem.

So, one suggestion is, to always RE-READ a question in case you get a WA verdict and you think “This question is too easy, I don’t think I am wrong”, which can happen a lot in easy questions. Especially if they are intentionally made with weird corner cases. And, also try to see if you have used every information they have provided. Although, it is still based on intuition. Sometimes they might give extra useless information, which you have to discard/neglect.

Anyway, Congratulations on solving it. Cheers!

1 Like

I think the statement was ambiguous. I wanted to make clear that if L>R then people should swap their values. Like if L=10 and R=20 then it also possible that L=20 and R=10, so in such case swap the values. Sorry guys for the inconvenience caused.

Here is the editorial for SHADOW: SHADOW - EDITORIAL