#include<stdio.h> #include<math.h> long long mod,t; long long sum(long long x,long long y) { t=x+y; if(x%2==0)x/=2;//x&1==0 不能用 else if(y%2==0)y/=2; else t/=2; x%=mod; y%=mod; t%=mod; return x*y%mod*t%mod ; } int main() { long long x1,x2,y1,y2; while(scanf("%lld %lld %lld %lld %lld",&x1,&y1,&x2,&y2,&mod)!=EOF) { //printf("%lld %lld %lld %lld\n",sum(x2,y2),sum(x1-1,y1-1),sum(x2,y1-1),sum(x1-1,y2)); printf("%lld\n",(sum(x2,y2)+sum(x1-1,y1-1)-sum(x2,y1-1)-sum(x1-1,y2)+2*mod)%mod); } return 0; }
**注意模运算时,对其他运算的影响,比如该题就不能随便除2;
模运算后,再相加相减需要注意是否被减数够减。