签到题????2018 = 2×1009;很明显吗????
只要找两边2 , 1009,2×1009的个数容赤一下就好了。。。
代码 :
#include
#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;
}