TSOJ--2018 江苏省省赛
[2018 江苏省大学生程序设计大赛]
K. 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
Constraint of original edition (省赛原题测试数据规模,非 TSOJ 此题的数据规模,下列数据 仅供参考 )
• 1 ≤ a ≤ b ≤ 10⁹, 1 ≤ c ≤ d ≤ 10⁹
• The number of tests cases does not exceed 10⁴.
题目大意: 在a,b区间和c,d区间内找一些数使得这些数的乘积是2018的倍数
题解 : 找2018的约数,有1,2,1009,2018这四个数,然后找它们的数量
#include<iostream>
#include<cstdio>
using namespace std;
long long Count(int n,int m) //用来求区间中2的倍数的个数
{
if(n%==&&m%==)
return ((m-n)/+);
else if(n%!=&&m%!=)
return ((m-n)/);
else
return ((m-n+)/);
}
int main()
{
int a,b,c,d;
long long ans,f1,f2;
while(scanf("%d%d%d%d",&a,&b,&c,&d)!=EOF)
{
ans=;
f1=Count(a,b);
f2=Count(c,d);
long long a18=d/-(c-)/;//区间中2018的倍数的个数
ans+=a18*(b-a+);
long long a19=d/-(c-)/-a18; //区间中1009的倍数的个数
ans+=a19*f1; long long a28=b/-(a-)/;
ans+=a28*(d-c+);
long long a29=b/-(a-)/-a28;
ans+=a29*f2; printf("%lld\n",ans-(a29*a18+a28*(a19+a18)));//最后要减去多乘的数
}
return ;
}
最新文章
- 玩转spring boot——AOP与表单验证
- 分布式缓存技术redis学习系列(五)——redis实战(redis与spring整合,分布式锁实现)
- xcode 工具学习笔记
- 转:设置Eclipse中的tab键为4个空格的完整方法
- JVM 小结
- linux 生成KEY的方法与使用
- 14 BasicHashTable基本哈希表类(一)——Live555源码阅读(一)基本组件类
- 黑马程序员_Java基础:实现多线程对共有数据的同步操作
- Solr特殊字符转义处理
- Android中“再按一次返回键退出程序”实现
- 将Winform程序快速转换为在浏览器中运行的程序
- ARM-Linux S5PV210 UART驱动(1)----用户手册中的硬件知识
- 通过Wifi调试Android应用
- 原生js实现的轮播图,易用+可多用
- c#控制台应用程序-“进入指定日期检查出星期几”
- ElasticSearch和Kibana 5.X集群的安装
- CentOS7 配置静态IP
- [LeetCode] 589. N-ary Tree Preorder Traversal_Easy
- codeforces.com/contest/251/problem/C
- php 实现 java com.sun.org.apache.xml.internal.security.utils.Base64 Byte数组加密