Product Modulo help!

Problem link

How to solve these kind of questions? I used BigInteger in java to find the product resulted in tle. Can someone help me or give a clue? Please, thanks in advance

1 Like

here answer is n%m always :slight_smile:

1 Like

How? Can you please explain?

easy buddy product of (a[i] * a[i+1] * a[i+2] ----- *a[n] )%a[i]=0
now in question we have to find sum for each i is (a[i]a[i+1]----- *a[n] +1 )%a[i] = (0+1)=1
now this 1 add upto n times
1+1+1+1------n times = n
now print n%m

1 Like

for ex : (5 * 4 * 6 * 3 )%5 =0 as one factor of 5 is present in multiplicants ie., 5
now (5* 4 * 6 * 3 +1 )%5 = 1%5 = 1
or (a+b)%m = (a%m+b%m)%m
(a-b)%m = (a%m-b%m + m)%m
(a*b)%m = (a%m * b%m)%m

1 Like

I don’t think this is correct.

1%1 is 0 and not 1

Damn bro… This is way basic math. Omg :pleading_face: thank you so much. Can you please tell me this one too
[https://www.hackerrank.com/contests/prayatna-20/challenges/card-game-2-1] . I did n/m and then checked divisibility by 2. I got WA. Thanks a lot bro

yes , so which part i said wrong ?

Ans is just
(sum (1\mod a[i]) )%m for 0 \le i \le n-1
Because,
(x*y*z) \mod x = 0
(x*y*z) \mod y = 0
(x*y*z) \mod z = 0

1 Like

if a[i] is 1 then its contribution will be zero right ?
because 1 modulo 1 is 0
1
5 2
1 1 1 1 1

Should be 0
Not 5%2

3 Likes

Seen you after a long time, really missed you @l_returns

2 Likes

:slight_smile: Same here

4 Likes

hell yes… i forgot :clap:

1 Like

Awwwwwwww :rofl::rofl::rofl::rofl::rofl:

They have weak test cases :frowning:

1 Like

Why? Your logic have AC?

yesss
print(n%m) :slight_smile:

1 Like

Damn… weak af… Can you please help me in this too… please please please

I divide the n/m and then checked whether it’s divisible by 2 or not. It passed half of the test cases… where must I have gone wrong?

Not weak, Wrong test cases LOL.
They also forgot it.
Test Case #3 fails with my soln

1 Like

:joy::joy::joy::rofl::rofl: bhai bhai