P2567 [SCOI2010]幸运数字
题目
做法
容斥+剪枝
先预处理幸运数字,别看数据范围这么大,其实也没几个,然后去掉倍数这种
然后处理相似数字,一眼的容斥,递归选数然后求出这些的公倍数容斥一下
玄学剪枝:从大到小排列,若公倍数大于范围退出,加速大于范围的情况
My complete code
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<string>
#include<cmath>
#include<ctime>
using namespace std;
typedef long long LL;
const int maxn=100000;
LL A,B;
int tot,cnt,ans;
LL a[maxn],num[maxn];
bool visit[maxn];
void First(int dep,int now,LL bit,LL x){
if(now>dep){
a[++tot]=bit;
return;
}
First(dep,now+1,bit+(x<<2)+(x<<1),(x<<3)+(x<<1)),
First(dep,now+1,bit+(x<<3),(x<<3)+(x<<1));
}
inline bool cmp(LL x,LL y){
return x>y;
}
inline LL Gcd(LL a,LL b){
while(b){
LL c=a%b;
a=b,b=c;
}
return a;
}
inline LL Calc(LL l,LL r,LL lcm){
return r/lcm-(l-1)/lcm;
}
void Dfs(int dep,int now,LL val){
if(val>B)
return;
if(dep>cnt){
if(now==0)
return;
ans+=Calc(A,B,val)*((now&1)?1:-1);
return;
}
Dfs(dep+1,now,val);
LL lcm=val/Gcd(val,num[dep]);
if(1.0*lcm*num[dep]<=B)
Dfs(dep+1,now+1,lcm*num[dep]);
}
int main(){
scanf("%lld%lld",&A,&B);
int t1=clock();
for(int i=1;i<=10;++i)
First(i,1,0,1);//printf("233");
for(int i=1;i<=tot;++i){
if(!visit[i])
num[++cnt]=a[i];
for(int j=i+1;j<=tot;++j)
if(a[j]%a[i]==0)
visit[j]=true;
}
sort(num+1,num+1+cnt,cmp);
Dfs(1,0,1ll);
printf("%lld\n",ans);
return 0;
}/*
1 10000000000
*/
P2567 [SCOI2010]幸运数字的更多相关文章
- P2567 [SCOI2010]幸运数字 DFS+容斥定理
P2567 [SCOI2010]幸运数字 题目描述 在中国,很多人都把6和8视为是幸运数字!lxhgww也这样认为,于是他定义自己的“幸运号码”是十进制表示中只包含数字6和8的那些号码,比如68,66 ...
- Luogu P2567 [SCOI2010]幸运数字 容斥+脑子
双倍经验:BZOJ 2393 Cirno的完美算数教室 做法:先把$[1,r]$中所有的幸运数字筛出来,然后用这些幸运数字来筛$[l,r]$中的近似幸运号码: 剪枝:当一个幸运数字$a[i]$是另一个 ...
- [洛谷P2567] SCOI2010 幸运数字
问题描述 在中国,很多人都把6和8视为是幸运数字!lxhgww也这样认为,于是他定义自己的"幸运号码"是十进制表示中只包含数字6和8的那些号码,比如68,666,888都是&quo ...
- BZOJ 1853: [Scoi2010]幸运数字
1853: [Scoi2010]幸运数字 Time Limit: 2 Sec Memory Limit: 64 MBSubmit: 2117 Solved: 779[Submit][Status] ...
- Bzoj 1853: [Scoi2010]幸运数字 容斥原理,深搜
1853: [Scoi2010]幸运数字 Time Limit: 2 Sec Memory Limit: 64 MBSubmit: 1774 Solved: 644[Submit][Status] ...
- bzoj 1853: [Scoi2010]幸运数字 容斥
1853: [Scoi2010]幸运数字 Time Limit: 2 Sec Memory Limit: 64 MBSubmit: 1170 Solved: 406[Submit][Status] ...
- bzoj1853[Scoi2010]幸运数字 容斥
1853: [Scoi2010]幸运数字 Time Limit: 2 Sec Memory Limit: 64 MBSubmit: 3027 Solved: 1128[Submit][Status ...
- BZOJ_2393_Cirno的完美算数教室&&BZOJ_1853_[Scoi2010]幸运数字 _深搜+容斥原理
BZOJ_2393_Cirno的完美算数教室&&BZOJ_1853_[Scoi2010]幸运数字 _深搜+容斥原理 题意: ~Cirno发现了一种baka数,这种数呢~只含有2和⑨两种 ...
- 【BZOJ 1853】 1853: [Scoi2010]幸运数字 (容斥原理)
1853: [Scoi2010]幸运数字 Time Limit: 2 Sec Memory Limit: 64 MBSubmit: 2472 Solved: 911 Description 在中国 ...
随机推荐
- block知识点
1.block引用局部变量的时候,该变量会作为常量编码到block中,在block中不能被修改. 2.使用 __block修饰的局部变量,不会作为常量被编码到block中,故而在block中可以被修改 ...
- js获取时间查并实现倒计时读条
<script type="text/javascript"> $().ready(function () {// 每增加一个切换,就要增加一行,tab1不变,其他的都 ...
- Docker iptables failed: iptables -t nat -A DOCKER -p tcp
Dokcer网络问题 因为操作或修该过iptables导致docker容器出现如下错误: [root@mysqlserver ~]# docker restart cvnavi-centos-tomc ...
- Github上的PHP开源资源汇总
依赖管理 ——用于依赖管理的包和框架 Composer/Packagist : 一个包和依赖管理器 Composer Installers: 一个多框架Composer库安装器 Pickle: 可以 ...
- bzoj 2458: [BeiJing2011]最小三角形 题解
[前言]话说好久没有写题解了.到暑假了反而忙.o(╯□╰)o [原题] 2458: [BeiJing2011]最小三角形 Time Limit: 10 Sec Memory Limit: 128 M ...
- iOS 获取LaunchImage启动图
iOS开发中,LaunchImage图片会根据手机机型的不同,自动匹配对应的图片,而我们如果想要拿到对应的图片,无法直接通过图片的名字获取该启动图,而需要通过以下方式 + (NSString *)ge ...
- APPLE ID随意转区到US或者HK.不需要信用卡
看到论坛有封釉想去US 或者HK 的商店下载大陆商店没有的APP.(比如 Tumblr) 但是现在在手机上或者是网页管理apple id 更改地区,需要输入付款信息. 现在教大家利用旧版的icloud ...
- [转载]Axure RP 7.0下载地址及安装说明
Axure RP是产品经理必备的原型制作工具,因为很多同学是新手,在这里整理一下axure7.0的下载.安装和汉化流程,希望能够帮到大家. Axure RP是美国Axure Software Solu ...
- Hadoop相关资料
http://blog.csdn.net/skywalker_only/article/details/40650427
- Hadoop2.6.0版本MapReudce示例之WordCount(一)
一.准备测试数据 1.在本地Linux系统/var/lib/Hadoop-hdfs/file/路径下准备两个文件file1.txt和file2.txt,文件列表及各自内容如下图所示: 2.在hdfs中 ...