Can you tell why (x * z * z) % MOD is different from (x * ( (z*z)%MOD) ) %
MOD
Again why ((x%MOD)*(z%MOD)*(z%MOD))%MOD is giving WA
I thought of a simple examples like
(100* 53*72) % 90
-- ((90+10)*53*72) % 90
-- (10*53*72)% 90 which is same as (100%90 * 53%90 * 72%90) % 90
Another
As far as modular arithmetic is concerned,
(x * z *z )%MOD = (x *(z *z)%MOD)%MOD = ((x%MOD)*(z%MOD)*(z%MOD))%MOD
But when you try to calculate *(x * z * z)%MOD*, the intermediate result of* (x
* z * z) *overflows the integer limit and hence gives the wrong result.
similarly, intermediate value
Just a MINOR change.
please change the RED line(I've marked it below) in your code by the
following line:
*return (x*((z*z)%MOD))%MOD;*
and enjoy an *ACCEPTED *verdict.*
*
*Wasif Hossain**
*
B.Sc. Student of Final Semester,
Computer Science and Engineering(CSE),
Bangladesh University of
I'm getting WA on the question : ZSUM-SPOJhttps://www.spoj.pl/problems/ZSUM/
Here is my code: Let me know if you can find the problem with the code
#includecstdio
#define MOD 1007
typedef unsigned long long u64;
using namespace std;
u64 modExp(u64 x, u64 y){
if(x==0)
return 0;