2018

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 507    Accepted Submission(s): 263

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

思路:

1.若x是偶数:1)若x是1009的倍数,则y可为[c,d]中任意数; 2)若x不是1009的倍数,则y必定为[c,d]中1009的倍数
2.若x是奇数:1)若x是1009的倍数,则y必定为[c,d]中2的倍数; 2)若x不是1009的倍数,则y必定为[c,d]中2018的倍数

AC代码:

#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<string>
#include<queue>
#include<utility>
#define ll long long
using namespace std;
const int maxn = 1e5+; int main(int argc, char const *argv[])
{
ll a,b,c,d;
while(~scanf("%lld %lld %lld %lld",&a,&b,&c,&d))
{
ll s1 = b-a+;
ll s2 = d-c+;
ll s1_odd = b/-(a-)/;
ll s1_1009 = b/-(a-)/; ll x1=(b/-(a-)/)*s2;
ll x2=(s1_odd-(b/-(a-)/))*(d/-(c-)/);
ll x3=(s1_1009-(b/-(a-)/))*(d/-(c-)/);
ll x4=((s1-s1_odd)-(s1_1009-(b/-(a-)/)))*(d/-(c-)/);
printf("%lld\n",x1+x2+x3+x4);
}
return ;
}

2018(容斥定理 HDU6286)的更多相关文章

  1. HDU 1796How many integers can you find(简单容斥定理)

    How many integers can you find Time Limit: 12000/5000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  2. Codeforces Round #330 (Div. 2) B. Pasha and Phone 容斥定理

    B. Pasha and Phone Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/595/pr ...

  3. hdu_5213_Lucky(莫队算法+容斥定理)

    题目连接:hdu_5213_Lucky 题意:给你n个数,一个K,m个询问,每个询问有l1,r1,l2,r2两个区间,让你选取两个数x,y,x,y的位置为xi,yi,满足l1<=xi<=r ...

  4. How Many Sets I(容斥定理)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3556 How Many Sets I Time Limit: 2 ...

  5. HDU - 4135 Co-prime 容斥定理

    题意:给定区间和n,求区间中与n互素的数的个数, . 思路:利用容斥定理求得先求得区间与n互素的数的个数,设表示区间中与n互素的数的个数, 那么区间中与n互素的数的个数等于.详细分析见求指定区间内与n ...

  6. BZoj 2301 Problem b(容斥定理+莫比乌斯反演)

    2301: [HAOI2011]Problem b Time Limit: 50 Sec  Memory Limit: 256 MB Submit: 7732  Solved: 3750 [Submi ...

  7. BZOJ2839 : 集合计数 (广义容斥定理)

    题目 一个有 \(N\) 个 元素的集合有 \(2^N\) 个不同子集(包含空集), 现在要在这 \(2^N\) 个集合中取出若干集合(至少一个), 使得它们的交集的元素个数为 \(K\) ,求取法的 ...

  8. HDU 1695 GCD 欧拉函数+容斥定理 || 莫比乌斯反演

    GCD Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  9. HDU 4135 Co-prime 欧拉+容斥定理

    Co-prime Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

随机推荐

  1. mobBUS

    1.今天听陈刚说起modBUS通信协议,这个还是第一次听说,究竟是什么东东,还是上网查查看吧 2.网上有C语言程序. http://blog.163.com/li_g888@126/blog/stat ...

  2. jquery删除当前行

    <tr><td><input type='hidden' name='annex' value="+rs+"><a href='javas ...

  3. HDBS之应用代码优化

    一.目录结构树 总体概述 代码检测工具sonar HDBS代码优化 总结开发注意点 二.总体概述 进入现在这家公司我的第一个任务就是对HDBS进行代码质量优化.HDBS可能大家不是很了解,现在给大家简 ...

  4. Can't connect to X11 window server using 'localhost:10.0' as the value of the DISPLAY variable.

    刚刚在一台Linux服务器上安装了jdk和Tomcat,然后部署了一个web项目,在项目中有个添加图片的功能,保存图片时报错 org.springframework.web.util.NestedSe ...

  5. mysql对查出来的值,在sql里面拼接我们想要拼接的内容

    MySQL中concat函数使用方法:CONCAT(str1,str2,…) 返回结果为连接参数产生的字符串.如有任何一个参数为NULL ,则返回值为 NULL. 注意:如果所有参数均为非二进制字符串 ...

  6. vue vue-router 完美实现前进刷新,后退不刷新。附scrollBehavior源码解析

    需求:在一个vue的项目中,我们需要从一个列表页面点击列表中的某一个详情页面,从详情页面返回不刷新列表,而从列表的上一个页面重新进入列表页面则需要刷新列表. 而浏览器的机制则是每一次的页面打开都会重新 ...

  7. PHP 获取客户端 IP 地址

    先来了解一个变量的含义: $_SERVER['REMOTE_ADDR']:浏览当前页面的用户计算机的ip地址 $_SERVER['HTTP_CLIENT_IP']:客户端的ip $_SERVER['H ...

  8. OpenCV-Python 视频读取

    import numpy as np import cv2 # 读取视频文件 cap = cv2.VideoCapture('./law.mp4') # 或者电影每秒的帧数 fps = cap.get ...

  9. Flask第三方组件之flask_session

    flask默认提供了session, 但是存在以下问题: ① session数据存在客户端, 不安全 ② 大小有限制 ③ 增加了客户端的压力 所以才产生了很多第三方的session机制, 我使用的是f ...

  10. 如何用SQL语句处理缓慢变化维(渐变维,拉链表)SCD-2?

    假设有一张居民维表,需要记录居民状态的变更历史,根据Kimball建模理论,设计居民维表如下: 另外在ODS中有居民信息的每日快照表(每天都记录一份居民的全量信息):O_USERINFO 如何将ODS ...