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 在中国 ...
随机推荐
- java System属性列表
http://blog.csdn.net/bryanliu1982/article/details/5205636 比如获取windows登录用户主目录 String usreHome = Syste ...
- NSNotification的几点说明
1.NSNotification消息的同步性 ①NSNotification使用的是同步操作.即如果你在程序中的A位置post了一个NSNotification,在B位置注册了一个observer,通 ...
- HDU 4738 Caocao's Bridges(找割边)
HDU 4738 Caocao's Bridges 题目链接 注意几个坑,可能重边,至少要派一个人去炸,没有连通的时候就不用炸了 代码: #include <cstdio> #includ ...
- 在CentOS 5下安装中文五笔
由于习惯使用五笔,需要在CentOS5 下安装中文五笔输入法. 刚装好的 CentOS 5默认是没有中文输入 法的.只能显示英文,有中文字符的文件名呈现乱码. 首先挂载CentOS的系统安装盘,在安装 ...
- Python内置函数之range()
range(stop)range(start,stop[,step]) 返回一个range对象,第三个参数的含义为:间隔的个数. range对象同时也是可迭代对象. >>> isin ...
- Android Studio 使用笔记:查看类结构和继承关系
选中类 ,按下F4,可以打开类的源代码 在 Eclipse 中我们可以使用 Ctrl + O 组合热键查看类的结构,Android Studio 中也可以做到. View -> Tool Win ...
- 走进科学之揭开神秘的"零拷贝"!
"零拷贝"这三个字,想必大家多多少少都有听过吧,这个技术在各种开源组件中都使用了,比如kafka,rocketmq,netty,nginx等等开源框架都在其中引用了这项技术 ...
- Android-BroadcastReceiver具体解释
什么是Broadcast Broadcast即广播,在Android广播是很重要的功能.比如我们想在系统开机之后做某些事情.监控手机的电量.监控手机的网络状态等等.这些功能都须要用到广播.当然我们也能 ...
- phpcms的基础知识和配置
一.设置界面 1.站点设置:相当于服务器上的站点 (1)站点修改:“关键词”和“描述”的修改,便于网络优化和搜索引擎对本网站的搜索. (2)点击站点后边的修改,模板的修改,引用自己模板 2.基本设置: ...
- Brain Network (easy)(并查集水题)
G - Brain Network (easy) Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & ...