MOD issues (FIRESC)

my code is:
vector int a;
.
.
.
long long prod=1;
for (auto i:a)
prod=(prod*i)%MOD;
cout<<prod;

My solution had got verdict WA when I used int instead of long long for prod.
can someone explain??

If you could give some more details about the code and possibly the question then we might help

1 Like

https://www.codechef.com/viewsolution/31967981

1 Like

The value of prod could become greater than 10e9 + 7 (hence the mod) which cant be stored in int. Which is why you are required to store it in long or long long.

But before updating prod, I have done the modulo, so the value of prod can’t be more than MOD.
correct me ,if I m wrong.

Oh yes. Kindly Pardon me

I tried for the submission now and got accepted. Might be a bug last time. :slight_smile:

thanks for being a helping hand. :slight_smile: :slight_smile:

Oh that’s great :slight_smile: .

That is wrong. It overflows immediately. So if prod was 10^9 and i is 5, it will become 5*10^9, and will overflow before you are even able to do mod.

1 Like

ohh, I thought it overflows while assigning. Thanks!!
But solution got accepted for int also. I think, They must work on the test cases.

You might have misread the verdict. Your only accepted solution declares prod as a long long.

The status just after submission is AC but in the “my submission” section, it is showing WA. I have checked it now.