Problem Description
Given a,b,c,d, find out the number of pairs of integers (x,y) where a≤x≤b,c≤y≤d and x⋅y is a multiple of 2018.
Input
The input consists of several test cases and is terminated by end-of-file.
Each test case contains four integers a,b,c,d.Output
For each test case, print an integer which denotes the result.
## Constraint
* 1≤a≤b≤109,1≤c≤d≤109
* The number of tests cases does not exceed 104.Sample Input
1 2 1 2018 1 2018 1 2018 1 1000000000 1 1000000000
Sample Output
3 6051 1485883320325200
AC代码:
- #include
- #include
- #include
- using namespace std;
-
- #define int long long
-
- signed main()
- {
- int a,b,c,d;
- while(cin>>a>>b>>c>>d)
- {
- int x1,x2,x1009,x2018;
- x1009=b/1009-(a-1)/1009;
- x2018=b/2018-(a-1)/2018;
- x2=b/2-(a-1)/2;
- x1=b-a+1-x2;
- x1009-=x2018;
- x1-=x1009;
- x2-=x2018;
-
- int y2,y,y2018,y1009;
- y1009=d/1009-(c-1)/1009;
- y2018=d/2018-(c-1)/2018;
- y=d-c+1;
- y2=d/2-(c-1)/2;
-
- printf("%lld\n",x1009*y2+x1*y2018+x2018*y+x2*y1009);
- }
- }