Submission #79177038 - Codeforces I got wa in this and it gets accepted as soon as I put (n+(i+a[i]%n))%n here Submission #79242347 - Codeforces can anyone tell me why is that I mean n+(i+a[i])%n should always give the same value as (n+(i+a[i])%n)%n can anyone help me with this
No. Let’s say i +a[i] =x.
Then it expands to
(n+x%n)%n
. So n is added first and then %n is done twice.
1 Like
but see x%n will always be smaller than n right and x%n will always be negative in the condition
so won’t n+x%n will always have a value between 0 to n
No.
n+x%n
is the same as (n+x)%n
which might be negative.
1 Like
won’t abs(x%n) will always be less than n?
Yes but then you will get WA. Because -3 \equiv 2 \mod 5
1 Like
ok i got it thanks