Where is the difference between the two method?

part2=((x%mod)*(y%mod))%mod;
part2=((z%mod)*part2)%mod; 
part2=((z%mod)((x%mod)(y%mod))%mod)%mod;
1st is Accepted and 2nd is Wrong answer
but why? Please help .Thnx in advance
Where is the difference between the two method?
part2=((x%mod)*(y%mod))%mod;
part2=((z%mod)*part2)%mod;
part2=((z%mod)((x%mod)(y%mod))%mod)%mod;
1st is Accepted and 2nd is Wrong answer
but why? Please help .Thnx in advance
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
(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;
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