2018
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 504 Accepted Submission(s): 262
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.
* 1≤a≤b≤1e9,1≤c≤d≤1e9
* The number of tests cases does not exceed 1e4.
* 1≤a≤b≤1e9,1≤c≤d≤1e9
* The number of tests cases does not exceed 1e4.
Sample Input
1 2 1 2018
1 2018 1 2018
1 1000000000 1 1000000000
Sample Output
讨论左边区间的可能:
1.2018的倍数
2.1009的倍数但不是2018的倍数
3.2的倍数但不是2018的倍数
4. 1的倍数但不是1009与2的倍数
右边区间分别讨论:
1.1的倍数
2.2的倍数
3.1009的倍数
4.2018的倍数
代码:
#include"bits/stdc++.h" #define ll long long #define cl(x) scanf("%lld",&x) #define pl(x) printf("%lld\n",x) using namespace std; int main() { ll a,b,c,d; while(scanf("%lld%lld%lld%lld",&a,&b,&c,&d)==4) { ll ans=0; ll a1,a2,a3; a1=(b/2018)-((a-1)/2018); a1*=d-c+1; a2=b/1009-(a-1)/1009-(b/2018-(a-1)/2018); a2*=d/2-(c-1)/2; a3=b/2-(a-1)/2-(b/2018-(a-1)/2018); a3*=d/1009-(c-1)/1009; ans+=(b-a+1-(b/2-(a-1)/2)-(b/1009-(a-1)/1009)+(b/2018-(a-1)/2018))*(d/2018-(c-1)/2018); ans+=a1+a2+a3; pl(ans); } }