Given a,b,c,da,b,c,d, find out the number of pairs of integers (x,y)(x,y) where a≤x≤b,c≤y≤da≤x≤b,c≤y≤dand x⋅yx⋅y is a multiple of 20182018.
Input
The input consists of several test cases and is terminated by end-of-file.
Each test case contains four integers a,b,c,da,b,c,d.
Output
For each test case, print an integer which denotes the result.
## Constraint
* 1≤a≤b≤109,1≤c≤d≤1091≤a≤b≤109,1≤c≤d≤109
* The number of tests cases does not exceed 104104.
Sample Input
1 2 1 2018 1 2018 1 2018 1 1000000000 1 1000000000
Sample Output
3 6051 1485883320325200
数学,题不难,但是纠结了好久
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
ll a,b,c,d;
ll f(ll x){
x/=1009;
if(x%2)return x/2+1;
return x/2;
}
int main()
{
while(~scanf("%lld%lld%lld%lld",&a,&b,&c,&d)){
ll sum=0;
sum+=(b/2018-(a-1)/2018)*(d-c+1); // 1
sum+=(d/2018-(c-1)/2018)*(b-a+1); // 2
sum-=(b/2018-(a-1)/2018)*(d/2018-(c-1)/2018); // 3
sum+=(f(b)-f(a-1))*(d/2-(c-1)/2-(d/2018-(c-1)/2018)); // 4
sum+=(f(d)-f(c-1))*(b/2-(a-1)/2-(b/2018-(a-1)/2018)); //5
printf("%lld\n",sum);
}
return 0;
}