HDU 6286 2018

Problem Description

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

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

 

Sample Input

 
 

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

 

Sample Output

 
 

3 6051 1485883320325200

思路:由于2018只有两个因子2和1009,于是我们可以单独对x进行讨论

        1、x为奇数:a、x为1009的倍数,此时y只能是2的倍数

                                b、x不为1009的倍数,此时y只能是2018的倍数

        2、x为偶数:a、x为2018的倍数,此时y可以为任何数

                                b、x不为2018的倍数,此时y只能是1009的倍数

AC代码:

#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;

#define int long long

signed main()
{
	int a,b,c,d;
	while(cin>>a>>b>>c>>d)
	{
		int x1,x2,x1009,x2018;
		x1009=b/1009-(a-1)/1009;
		x2018=b/2018-(a-1)/2018;
		x2=b/2-(a-1)/2;
		x1=b-a+1-x2;
		x1009-=x2018;
		x1-=x1009;
		x2-=x2018;
		
		int y2,y,y2018,y1009;
		y1009=d/1009-(c-1)/1009;
		y2018=d/2018-(c-1)/2018;
		y=d-c+1;
		y2=d/2-(c-1)/2;
		
		printf("%lld\n",x1009*y2+x1*y2018+x2018*y+x2*y1009);
	}
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Double.Qing

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值