hdu - 6286 2018

 

题目链接
https://vjudge.net/problem/HDU-6286

#include<cstdio>
#include<stack>
#include<queue>
#include<cmath>
#include<climits>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#define ll_INF 233333333333333
#define INF = 0x3f3f3f3f
#define max(a, b) a >= b ? a : b
#define min(a, b) a <= b ? a : b
#define _test printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n")
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int maxn = 1000005;
ll tool(int a, int b, int n) {
    return b/n - (a-1)/n;//a-1避免a能被n整除时没有被算上
}//不返回ll输入最后一组数据相乘的时候会越界
int main(void) {
    int a, b, c, d;
    while(cin >> a >> b >> c >> d) {
        ll sum = 0;
        sum += (tool(a, b, 2018) * (d-c+1) + (b-a+1) * tool(c, d, 2018));//2018的倍数 * 任意数 && 任意数 * 2018的倍数
        sum += (tool(a, b, 1009) - tool(a, b, 2018)) * (tool(c, d, 2) - tool(c, d, 2018));//是1009的倍数且不是2018的倍数 * 是2的倍数且不是2018的倍数
        sum += (tool(a, b, 2) - tool(a, b, 2018)) * (tool(c, d, 1009) - tool(c, d, 2018));//是2的倍数且不是2018的倍数 * 是1009的倍数且不是2018的倍数
        sum -= tool(a, b, 2018) * tool(c, d, 2018);//减掉上面少减的2018的倍数 *2018的倍数
        cout << sum << endl;
    }
    return 0;
}
posted @ 2019-11-23 12:28  shuitiangong  阅读(133)  评论(0编辑  收藏  举报