[2018 江苏省大学生程序设计大赛]JSCPC2018K. 2018 (测试数据范围有扩大)

 

Problem

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.

Output

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

Constraint

• Qing Jiang felt that the original edition of the test cases is too easy, so he enlarged the scope of data. The current edition is:

• 1 ≤ a ≤ b ≤ 2³¹ - 1, 1 ≤ c ≤ d ≤ 2³¹ - 1

• The number of tests cases is around at 1·10⁵.

Sample Input

1 2 1 2018

1 2018 1 2018

1 1000000000 1 1000000000

Sample Output

3

6051

1485883320325200

 

/*先找1009的倍数有a个,和2018倍数的有b个,a*偶数,b*任何数,注意:偶数里面也包括2018的倍数,任意数也包括1009的倍数*/ 
#include<iostream>
using namespace std;
long long all2018(long long xx,long long yy);//用于求两个区间段类含有2018的倍数的数有多个。 
long long all1009(long long xx,long long yy,long long all_of_2018);// 用于求两个区间段类含有1009的倍数的数有多少个。 
int main(){
    long long a,b,c,d;
    while(cin>>a>>b>>c>>d)
    {
    //x表示含有1009的倍数的数的个数。 
    //x1表示含有2018的倍数的数的个数。
    //y表示含有1009的倍数的数的个数。
    //y1表示含有2018的倍数的数的个数。
    //all1,all2表示含有偶数的个数。 
    long long x1,y1,x,y,all1,all2,val;
    x1=all2018(a,b);
    y1=all2018(c,d);
    x=all1009(a,b,x1);
    y=all1009(c,d,y1);
    all1=(b-a+1)/2;
    all2=(d-c+1)/2;
    if((b==a&&b%2==0)||(b%2==0&&a%2==0))
    all1++;
    if((c==d&&c%2==0)||(d%2==0&&c%2==0))
    all2++;
    val=x*all2+x1*(d-c+1)+y*all1+y1*(b-a+1)-x1*y1-y*x1-x*y1;
    cout<<val<<endl;
    }
    return 0;
}

long long all2018(long long xx,long long yy)
{
    long long all;
    all=yy/2018-xx/2018;
    if(xx>=2018&&yy>=2018)
    {
        if(xx%2018==0&&yy%2018==0)
        all++;
        else if(xx%2018==0&&yy%2018!=0)
        all++;
    }
    return all;
}

long long all1009(long long xx,long long yy,long long all_of_2018)
{
    long long all;
    all=yy/1009-xx/1009;
    if(yy>=1009&&xx>=1009)
    {
        if(xx%1009==0&&yy%1009==0)
        all++;
        else if(xx%1009==0&&yy%1009!=0)
        all++;
    }
    return all-all_of_2018;
}
 
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值