Where is the difference between the two method?

Where is the difference between the two method?

  1. part2=((x%mod)*(y%mod))%mod;
    part2=((z%mod)*part2)%mod;

  2. part2=((z%mod)((x%mod)(y%mod))%mod)%mod;

1st is Accepted and 2nd is Wrong answer :stuck_out_tongue:
but why? Please help .Thnx in advance :slight_smile:

1.part2=((x%mod)(y%mod))%mod; part2=((z%mod)part2)%mod;

In this, you are taking the mod with ((x%mod)(y%mod))%mod

where as in

  1. part2=((z%mod)((x%mod)(y%mod))%mod)%mod;

(z%mod) is first multiplied by ((x%mod)(y%mod))

(((z%mod)((x%mod)(y%mod)))%mod)

So, in order to get the correct answer in the second case try this:-

((z%mod)(((x%mod)(y%mod))%mod))%mod;

can you please explain more simply please? @mayank12559

The problem in the second case is only with the braces. Try to put (((x%mod)(y%mod))%mod)) in a separate brace and then multiply it with (z%mod) and you will get the correct answer.

Thanks mayank12559 :slight_smile:

//