2018
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 243 Accepted Submission(s): 127
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.
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.
## 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
Source
签到题????2018 = 2×1009;很明显吗????
只要找两边2 , 1009,2×1009的个数容赤一下就好了。。。
代码 :
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 1e5+7;
ll prim[maxn], cas[maxn], numcas[maxn];
bool vis[maxn];
int cnt = 0, tot = 0;
ll a, b, c, d, a1, b1, c1, s1, a2, b2, c2, s;
void FIND(ll a)
{
ll k = a;
for(int i = 0; i < cnt&&k > 1&&prim[i]*prim[i] <= k; i++)
{
if(k%prim[i] == 0)
{
cas[tot] = prim[i];
while(k%prim[i] == 0)
{
k /= prim[i];
numcas[tot]++;
}
tot++;
}
}
if(k > 1) {
cas[tot] = k;
numcas[tot++] = 1;
}
}
void print()
{
for(int i = 0; i < tot; i++)
{
printf("%d %d\n", cas[i], numcas[i]);
}
}
void init()
{
memset(vis, 0, sizeof(vis));
memset(cas, 0, sizeof(cas));
memset(numcas, 0, sizeof(numcas));
for(int i = 2; i*i < maxn; i++)
if(!vis[i])
for(int j = i*i; j < maxn; j+=i)
vis[j] = true;
for(int i = 2; i < maxn; i++)
if(!vis[i]) prim[cnt++] = i;
FIND(2018);
print();
}
int main()
{
//init();
//freopen("in.txt", "r", stdin);
while(~scanf("%lld%lld%lld%lld", &a, &b, &c, &d))
{
c1 = b/(2*1009) - (a - 1)/(2*1009);
a1 = b/2 - (a - 1)/2 - c1;
b1 = b/1009 - (a - 1)/1009 - c1;
s1 = b - a + 1 - a1 - b1 - c1;
c2 = d/(2*1009) - (c - 1)/(2*1009);
a2 = d/2 - (c - 1)/2 - c2;
b2 = d/1009 - (c - 1)/1009 - c2;
s = d - c + 1;
printf("%lld\n", a1*(b2+c2) + b1*(a2+c2) + c1*s + c2*s1);
}
return 0;
}