2018/8/8

1 篇文章 0 订阅

Given a,b,c,da,b,c,d, find out the number of pairs of integers (x,y)(x,y) where a≤x≤b,c≤y≤da≤x≤b,c≤y≤dand x⋅yx⋅y is a multiple of 20182018. 

Input

The input consists of several test cases and is terminated by end-of-file. 

Each test case contains four integers a,b,c,da,b,c,d. 

Output

For each test case, print an integer which denotes the result. 

## Constraint 

* 1≤a≤b≤109,1≤c≤d≤1091≤a≤b≤109,1≤c≤d≤109 
* The number of tests cases does not exceed 104104. 

Sample Input

1 2 1 2018
1 2018 1 2018
1 1000000000 1 1000000000

Sample Output

3
6051
1485883320325200

 

数学,题不难,但是纠结了好久

#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;

ll a,b,c,d;

ll f(ll x){
    x/=1009;
    if(x%2)return x/2+1;
    return x/2;
}

int main()
{
    while(~scanf("%lld%lld%lld%lld",&a,&b,&c,&d)){
        ll sum=0;
        sum+=(b/2018-(a-1)/2018)*(d-c+1); // 1
        sum+=(d/2018-(c-1)/2018)*(b-a+1); // 2
        sum-=(b/2018-(a-1)/2018)*(d/2018-(c-1)/2018); // 3
        sum+=(f(b)-f(a-1))*(d/2-(c-1)/2-(d/2018-(c-1)/2018)); // 4
        sum+=(f(d)-f(c-1))*(b/2-(a-1)/2-(b/2018-(a-1)/2018)); //5
        printf("%lld\n",sum);
    }

    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值