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

here answer is n%m always

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

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

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

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

Same here

hell yes… i forgot

Awwwwwwww

They have weak test cases

Why? Your logic have AC?

yesss

print(n%m)

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

bhai bhai