ZOJ 3233 Lucky Number
Lucky Number
This problem will be judged on ZJU. Original ID: 3233
64-bit integer IO format: %lld Java class name: Main
Watashi loves M mm very much. One day, M mm gives Watashi a chance to choose a number between low and high, and if the choosen number is lucky, M mm will marry him.
M mm has 2 sequences, the first one is BLN (Basic Lucky Numbers), and the second one is BUN (Basic Unlucky Numbers). She says that a number is lucky if it's divisible by at least one number from BLN and not divisible by at least one number from BUN.
Obviously, Watashi doesn't know the numbers in these 2 sequences, and he asks M mm that how many lucky number are there in [low, high]?
Please help M mm calculate it, meanwhile, tell Watashi what is the probability that M mm marries him.
Input
The first line of each test case contains the numbers NBLN (1 <= NBLN <= 15), NBUN (1 <= NBUN <= 500), low, high (1 <= low <= high <= 1018).
The second and third line contain NBLN and NBUN integers, respectively. Each integer in sequences BLN and BUN is from interval [1, 32767].
The last test case is followed by four zero.
The input will contain no more than 50 test cases.
Output
For each test case output one number, the number of lucky number between low and high.
Sample Input
2 1 70 81
2 3
5
0 0 0 0
Sample Output
5
Hint
The lucky numbers in the sample are 72, 74, 76, 78, 81.
Source
Author
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = ;
LL a[maxn],b[maxn],low,high,n,m;
LL LCM(LL a,LL b){
return a/__gcd(a,b)*b;
}
int main(){
ios::sync_with_stdio(false);
cin.tie();
while(cin>>n>>m>>low>>high,n||m||low||high){
for(int i = ; i < n; ++i) cin>>a[i];
LL q = ;
for(int j = ; j < m; ++j){
cin>>b[j];
q = LCM(q,b[j]);
}
LL ret = ;
for(int i = ; i < (<<n); ++i){
LL p = ;
int cnt = ;
for(int j = ; j < n; ++j){
if((i>>j)&){
cnt++;
p = LCM(p,a[j]);
}
}
if(q < ){
if(cnt&) ret += high/p - (low-)/p;
else ret -= high/p - (low - )/p;
continue;
}
LL s = LCM(p,q);
if(cnt&) ret += high/p - (low - )/p - (high/s - (low-)/s);
else ret -= high/p - (low - )/p - (high/s - (low-)/s);
}
printf("%lld\n",ret);
}
return ;
}
ZOJ 3233 Lucky Number的更多相关文章
- ZOJ 3233 Lucky Number --容斥原理
这题被出题人给活活坑了,题目居然理解错了..哎,不想多说. 题意:给两组数,A组为幸运基数,B组为不幸运的基数,问在[low,high]区间内有多少个数:至少被A组中一个数整除,并且不被B中任意一个数 ...
- 枚举 + 进制转换 --- hdu 4937 Lucky Number
Lucky Number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)To ...
- SCU3502 The Almost Lucky Number
Description A lucky number is a number whose decimal representation contains only the digits \(4\) a ...
- HDOJ 4937 Lucky Number
当进制转换后所剩下的为数较少时(2位.3位),相应的base都比較大.能够用数学的方法计算出来. 预处理掉转换后位数为3位后,base就小于n的3次方了,能够暴力计算. . .. Lucky Numb ...
- 题目1380:lucky number
转载请注明文本链接 http://blog.csdn.net/yangnanhai93/article/details/40441709 题目链接地址:http://ac.jobdu.com/prob ...
- HDU 3346 Lucky Number
水题 #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> us ...
- 九度oj 题目1380:lucky number
题目描述: 每个人有自己的lucky number,小A也一样.不过他的lucky number定义不一样.他认为一个序列中某些数出现的次数为n的话,都是他的lucky number.但是,现在这个序 ...
- 『NYIST』第九届河南省ACM竞赛队伍选拔赛[正式赛二]- Nearly Lucky Number(Codeforces Beta Round #84 (Div. 2 Only)A. Nearly)
A. Nearly Lucky Number time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- B - Nearly Lucky Number
Problem description Petya loves lucky numbers. We all know that lucky numbers are the positive integ ...
随机推荐
- bzoj3907 网格 & bzoj2822 [AHOI2012]树屋阶梯——卡特兰数+高精度
题目:bzoj3907:https://www.lydsy.com/JudgeOnline/problem.php?id=3907 bzoj2822:https://www.lydsy.com/Jud ...
- oracle数据库简单操作
导入某用户所有表和数据:imp sgp/sgp@192.168.0.99:1521/orcl file=sgp20161025.dmp full=y 导出指定表及数据:exp sgp/sgp@192. ...
- ural 1017. Staircases(dp)
http://acm.timus.ru/problem.aspx?space=1&num=1017 题意:有n块砖,要求按照严格递增的个数摆放成楼梯,求楼梯的摆放种类数. 思路:状态转移方程: ...
- 我们的微信小程序开发
基于微信小程序的系统开发准备工作 腾讯推出微信小程序也有一段时间了,在各种行业里面也都掀起一阵阵的热潮,很多APP应用被简化为小程序的功能迅速推出,同时也根据小程序的特性推出各种独具匠心的应用,相对传 ...
- [Swift通天遁地]七、数据与安全-(19)使用Swift实现原生的SHA1加密
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- Akka源码分析-Remote-发消息
上一篇博客我们介绍了remote模式下Actor的创建,其实与local的创建并没有太大区别,一般情况下还是使用LocalActorRef创建了Actor.那么发消息是否意味着也是相同的呢? 既然ac ...
- 网络简要<入门篇>
OSI七层 网络的含义:两个不在同一地理位置的主机(终端),通过传输介质和通信协议,实现通信和资源共享. 网络四要素:终端,传输介质 ,通信协议,资源 网络分类: 以范围分类:LAN网(局域网,以太网 ...
- 点击文字弹出一个DIV层窗口代码 【或FORM表单 并且获取点击按钮的ID值】
点击不同按钮咨询不同的 专家 <?php for($i=1;$i<5;$i++){ $uid=$i; //用户ID ?> <a class="a_click" ...
- EF--DBFirst
EF框架有三种基本的方式:DB First,Model First,Code First.这里简单的说一下DB First,适合没有基础的同学照着做,学习基础的东西. DatabaseFirst就是围 ...
- mysql使用出现错误:mysqld dead but subsys locked
现象: 登陆时候出现如下信息 [root@localhost home]# mysql -uroot -p123456mysql: [Warning] Using a password on the ...