 # Product Modulo help!

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 1 Like

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 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 Same here

4 Likes

hell yes… i forgot 1 Like

Awwwwwwww     They have weak test cases 1 Like

yesss
print(n%m) 1 Like     bhai bhai