2018 ccpc湘潭邀請賽 K. 2018 [思維+容赤]
阿新 • • 發佈:2019-01-23
2018
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 243 Accepted Submission(s): 127
Problem DescriptionGiven a
InputThe input consists of several test cases and is terminated by end-of-file.
Each test case contains four integers a,b,c,d.
OutputFor each test case, print an integer which denotes the result.
## Constraint
* 1
* The number of tests cases does not exceed 104.
Sample Input1 2 1 2018 1 2018 1 2018 1 1000000000 1 1000000000
Sample Output3 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; }