BZOJ_2393_Cirno的完美算数教室&&BZOJ_1853_[Scoi2010]幸运数字 _深搜+容斥原理

题意:

~Cirno发现了一种baka数,这种数呢~只含有2和⑨两种数字~~

现在Cirno想知道~一个区间中~~有多少个数能被baka数整除

分析:

基本思路是找到1e10以内所有的baka数,如果a[i]%a[j]==0则把a[i]删掉

每个方案的lcm的贡献是r/lcm-(l-1)/lcm,深搜每一种情况,用容斥原理确定正负

考虑优化,从大到小枚举baka数,当lcm大于r时返回

代码:

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
using namespace std;
#define LL long long
LL a[2000]={0,6ll,8ll,68ll,86ll,668ll,686ll,866ll,868ll,886ll,6668ll,6686ll,6866ll,6886ll,8666ll,8668ll,8866ll,66668ll,66686ll,66866ll,66868ll,66886ll,68666ll,68668ll,68686ll,68866ll,86666ll,86668ll,86686ll,86866ll,88868ll,88886ll,666668ll,666686ll,666866ll,666868ll,666886ll,668666ll,668686ll,668866ll,686666ll,686668ll,686866ll,688666ll,688868ll,688886ll,866666ll,866668ll,866686ll,868666ll,868886ll,886666ll,886868ll,888668ll,888686ll,888866ll,888868ll,888886ll,6666668ll,6666686ll,6666866ll,6666868ll,6668666ll,6668668ll,6668686ll,6668866ll,6686666ll,6686668ll,6686686ll,6686866ll,6688666ll,6688868ll,6688886ll,6866666ll,6866668ll,6866686ll,6866866ll,6868666ll,6868868ll,6868886ll,6886666ll,6886868ll,6886886ll,6888668ll,6888866ll,6888868ll,6888886ll,8666666ll,8666686ll,8666866ll,8668666ll,8668868ll,8686666ll,8686868ll,8686886ll,8688668ll,8688686ll,8688866ll,8688868ll,8688886ll,8866666ll,8866868ll,8866886ll,8868668ll,8868686ll,8868866ll,8868868ll,8868886ll,8886668ll,8886686ll,8886866ll,8886868ll,8886886ll,8888666ll,8888668ll,8888686ll,8888866ll,66666668ll,66666686ll,66666866ll,66666868ll,66666886ll,66668666ll,66668668ll,66668686ll,66668866ll,66686666ll,66686686ll,66686866ll,66688666ll,66688868ll,66688886ll,66866666ll,66866668ll,66866866ll,66868666ll,66868868ll,66886666ll,66886868ll,66886886ll,66888668ll,66888686ll,66888866ll,66888868ll,66888886ll,68666666ll,68666668ll,68666686ll,68668666ll,68668868ll,68668886ll,68686666ll,68686886ll,68688668ll,68688686ll,68688866ll,68688868ll,68688886ll,68866666ll,68866868ll,68868668ll,68868686ll,68868866ll,68868868ll,68886668ll,68886686ll,68886866ll,68886868ll,68886886ll,68888668ll,68888686ll,68888866ll,86666666ll,86666668ll,86666686ll,86666866ll,86668868ll,86668886ll,86686666ll,86686868ll,86686886ll,86688686ll,86688866ll,86688868ll,86688886ll,86866666ll,86866868ll,86866886ll,86868668ll,86868868ll,86868886ll,86886668ll,86886686ll,86886866ll,86886868ll,86886886ll,86888666ll,86888668ll,86888686ll,86888866ll,88666666ll,88666868ll,88666886ll,88668686ll,88668868ll,88668886ll,88686668ll,88686686ll,88686866ll,88686868ll,88686886ll,88688666ll,88688668ll,88688686ll,88688866ll,88866668ll,88866866ll,88866868ll,88866886ll,88868666ll,88868668ll,88868686ll,88868866ll,88886666ll,88886668ll,88886686ll,88886866ll,88888666ll,88888868ll,88888886ll,666666686ll,666666866ll,666666868ll,666666886ll,666668666ll,666668686ll,666668866ll,666686666ll,666686668ll,666686686ll,666686866ll,666688666ll,666688868ll,666688886ll,666866666ll,666866668ll,666866686ll,666866866ll,666868666ll,666868868ll,666868886ll,666886666ll,666886868ll,666886886ll,666888668ll,666888686ll,666888866ll,666888868ll,666888886ll,668666666ll,668666668ll,668666686ll,668666866ll,668668666ll,668668868ll,668668886ll,668686666ll,668686868ll,668686886ll,668688668ll,668688686ll,668688866ll,668688868ll,668688886ll,668866666ll,668866868ll,668866886ll,668868668ll,668868686ll,668868868ll,668868886ll,668886668ll,668886686ll,668886866ll,668886868ll,668886886ll,668888666ll,668888668ll,668888686ll,668888866ll,686666666ll,686666668ll,686666686ll,686666866ll,686668666ll,686668868ll,686668886ll,686686666ll,686686868ll,686686886ll,686688668ll,686688686ll,686688866ll,686688868ll,686688886ll,686866666ll,686866868ll,686866886ll,686868668ll,686868686ll,686868866ll,686868868ll,686868886ll,686886668ll,686886686ll,686886866ll,686886868ll,686886886ll,686888666ll,686888668ll,686888686ll,686888866ll,688666868ll,688666886ll,688668668ll,688668686ll,688668866ll,688668868ll,688668886ll,688686668ll,688686686ll,688686866ll,688686868ll,688686886ll,688688666ll,688688668ll,688688866ll,688866668ll,688866686ll,688866866ll,688866868ll,688866886ll,688868666ll,688868668ll,688868866ll,688886666ll,688886668ll,688886686ll,688886866ll,688888666ll,688888868ll,688888886ll,866666666ll,866666668ll,866666686ll,866666866ll,866668666ll,866668868ll,866668886ll,866686666ll,866686868ll,866686886ll,866688668ll,866688686ll,866688866ll,866688868ll,866688886ll,866866666ll,866866868ll,866866886ll,866868668ll,866868686ll,866868866ll,866868868ll,866868886ll,866886668ll,866886686ll,866886866ll,866886868ll,866886886ll,866888666ll,866888668ll,866888866ll,868666666ll,868666868ll,868666886ll,868668668ll,868668686ll,868668866ll,868668868ll,868686668ll,868686686ll,868686866ll,868686868ll,868686886ll,868688668ll,868688686ll,868688866ll,868866866ll,868866868ll,868866886ll,868868666ll,868868668ll,868868686ll,868868866ll,868886666ll,868886668ll,868886686ll,868886866ll,868888666ll,868888868ll,868888886ll,886666666ll,886666868ll,886666886ll,886668668ll,886668866ll,886668868ll,886668886ll,886686668ll,886686686ll,886686866ll,886686868ll,886686886ll,886688666ll,886688668ll,886688686ll,886688866ll,886866668ll,886866686ll,886866866ll,886866868ll,886866886ll,886868666ll,886868668ll,886868686ll,886868866ll,886886666ll,886886686ll,886886866ll,886888666ll,886888868ll,886888886ll,888666668ll,888666686ll,888666866ll,888666868ll,888666886ll,888668666ll,888668668ll,888668686ll,888668866ll,888686666ll,888686668ll,888686686ll,888686866ll,888688666ll,888688868ll,888688886ll,888866666ll,888866668ll,888866686ll,888866866ll,888868666ll,888868886ll,888886666ll,888886868ll,888886886ll,888888668ll,888888686ll,888888866ll,888888868ll,888888886ll,6666666668ll,6666666686ll,6666666866ll,6666666868ll,6666666886ll,6666668666ll,6666668668ll,6666668686ll,6666668866ll,6666686666ll,6666686668ll,6666686686ll,6666686866ll,6666688666ll,6666688886ll,6666866666ll,6666866686ll,6666866866ll,6666868666ll,6666868868ll,6666868886ll,6666886666ll,6666886868ll,6666886886ll,6666888668ll,6666888686ll,6666888866ll,6666888868ll,6666888886ll,6668666666ll,6668666668ll,6668666866ll,6668668666ll,6668668868ll,6668668886ll,6668686666ll,6668686868ll,6668686886ll,6668688686ll,6668688866ll,6668688868ll,6668688886ll,6668866666ll,6668866868ll,6668866886ll,6668868668ll,6668868686ll,6668868866ll,6668868886ll,6668886668ll,6668886686ll,6668886866ll,6668886868ll,6668886886ll,6668888666ll,6668888668ll,6668888686ll,6668888866ll,6686666666ll,6686666686ll,6686668666ll,6686668868ll,6686668886ll,6686686666ll,6686686868ll,6686686886ll,6686688668ll,6686688686ll,6686688866ll,6686688868ll,6686688886ll,6686866666ll,6686866886ll,6686868668ll,6686868686ll,6686868866ll,6686868868ll,6686868886ll,6686886668ll,6686886686ll,6686886866ll,6686886868ll,6686886886ll,6686888666ll,6686888668ll,6686888686ll,6686888866ll,6688666666ll,6688666868ll,6688668668ll,6688668686ll,6688668866ll,6688668868ll,6688668886ll,6688686668ll,6688686686ll,6688686866ll,6688686868ll,6688686886ll,6688688666ll,6688688668ll,6688688686ll,6688688866ll,6688866668ll,6688866686ll,6688866866ll,6688866868ll,6688866886ll,6688868666ll,6688868668ll,6688868686ll,6688868866ll,6688886666ll,6688886668ll,6688886686ll,6688886866ll,6688888666ll,6688888868ll,6688888886ll,6866666666ll,6866666668ll,6866666686ll,6866666866ll,6866668868ll,6866668886ll,6866686666ll,6866686868ll,6866686886ll,6866688668ll,6866688866ll,6866688868ll,6866688886ll,6866866666ll,6866866868ll,6866866886ll,6866868686ll,6866868866ll,6866868868ll,6866868886ll,6866886668ll,6866886686ll,6866886866ll,6866886868ll,6866886886ll,6866888666ll,6866888668ll,6866888686ll,6866888866ll,6868666666ll,6868666868ll,6868666886ll,6868668668ll,6868668866ll,6868668868ll,6868668886ll,6868686668ll,6868686686ll,6868686866ll,6868686886ll,6868688666ll,6868688668ll,6868688686ll,6868688866ll,6868866668ll,6868866686ll,6868866866ll,6868866868ll,6868866886ll,6868868666ll,6868868668ll,6868868686ll,6868868866ll,6868886666ll,6868886668ll,6868886686ll,6868886866ll,6868888666ll,6868888868ll,6886666666ll,6886666868ll,6886666886ll,6886668668ll,6886668686ll,6886668868ll,6886668886ll,6886686668ll,6886686686ll,6886686866ll,6886686868ll,6886686886ll,6886688666ll,6886688668ll,6886688686ll,6886688866ll,6886866686ll,6886866866ll,6886866868ll,6886866886ll,6886868666ll,6886868668ll,6886868686ll,6886868866ll,6886886666ll,6886886668ll,6886886686ll,6886886866ll,6886888666ll,6886888868ll,6886888886ll,6888666668ll,6888666686ll,6888666866ll,6888666868ll,6888666886ll,6888668666ll,6888668686ll,6888668866ll,6888686666ll,6888686668ll,6888686686ll,6888686866ll,6888688868ll,6888688886ll,6888866666ll,6888866668ll,6888866866ll,6888868666ll,6888868868ll,6888868886ll,6888886666ll,6888886868ll,6888886886ll,6888888668ll,6888888686ll,6888888866ll,6888888868ll,6888888886ll,8666666666ll,8666666668ll,8666666686ll,8666666866ll,8666668666ll,8666668868ll,8666668886ll,8666686868ll,8666686886ll,8666688668ll,8666688686ll,8666688866ll,8666688868ll,8666688886ll,8666866666ll,8666866868ll,8666866886ll,8666868686ll,8666868866ll,8666868868ll,8666868886ll,8666886686ll,8666886866ll,8666886868ll,8666886886ll,8666888666ll,8666888668ll,8666888686ll,8666888866ll,8668666666ll,8668666868ll,8668666886ll,8668668668ll,8668668686ll,8668668866ll,8668668868ll,8668668886ll,8668686668ll,8668686866ll,8668686868ll,8668686886ll,8668688666ll,8668688668ll,8668688686ll,8668688866ll,8668866668ll,8668866686ll,8668866866ll,8668866868ll,8668866886ll,8668868666ll,8668868668ll,8668868686ll,8668868866ll,8668886666ll,8668886668ll,8668886686ll,8668886866ll,8668888868ll,8668888886ll,8686666666ll,8686666886ll,8686668668ll,8686668686ll,8686668866ll,8686668868ll,8686668886ll,8686686668ll,8686686686ll,8686686868ll,8686686886ll,8686688666ll,8686688668ll,8686688686ll,8686688866ll,8686866668ll,8686866686ll,8686866866ll,8686866868ll,8686866886ll,8686868666ll,8686868668ll,8686868866ll,8686886666ll,8686886668ll,8686886686ll,8686886866ll,8686888666ll,8686888868ll,8686888886ll,8688666668ll,8688666686ll,8688666866ll,8688666868ll,8688666886ll,8688668668ll,8688668686ll,8688668866ll,8688686666ll,8688686668ll,8688686686ll,8688686866ll,8688688666ll,8688688868ll,8688688886ll,8688866666ll,8688866686ll,8688866866ll,8688868666ll,8688868868ll,8688868886ll,8688886666ll,8688886868ll,8688886886ll,8688888668ll,8688888686ll,8688888866ll,8688888868ll,8688888886ll,8866666666ll,8866666868ll,8866666886ll,8866668668ll,8866668686ll,8866668866ll,8866668868ll,8866686686ll,8866686866ll,8866686868ll,8866686886ll,8866688668ll,8866688686ll,8866688866ll,8866866668ll,8866866866ll,8866866886ll,8866868666ll,8866868668ll,8866868686ll,8866868866ll,8866886666ll,8866886668ll,8866886686ll,8866886866ll,8866888666ll,8866888868ll,8866888886ll,8868666668ll,8868666686ll,8868666866ll,8868666868ll,8868666886ll,8868668668ll,8868668686ll,8868668866ll,8868686666ll,8868686668ll,8868686686ll,8868686866ll,8868688666ll,8868688868ll,8868688886ll,8868866666ll,8868866668ll,8868866686ll,8868866866ll,8868868666ll,8868868868ll,8868868886ll,8868886666ll,8868886868ll,8868886886ll,8868888668ll,8868888686ll,8868888866ll,8868888868ll,8868888886ll,8886666668ll,8886666686ll,8886666866ll,8886666868ll,8886666886ll,8886668666ll,8886668668ll,8886668686ll,8886668866ll,8886686666ll,8886686668ll,8886686686ll,8886686866ll,8886688666ll,8886688886ll,8886866666ll,8886866668ll,8886866686ll,8886866866ll,8886868666ll,8886868868ll,8886868886ll,8886886666ll,8886886868ll,8886886886ll,8886888686ll,8886888866ll,8886888886ll,8888666666ll,8888666668ll,8888666686ll,8888666866ll,8888668666ll,8888668868ll,8888668886ll,8888686666ll,8888686868ll,8888686886ll,8888688668ll,8888688686ll,8888688866ll,8888688868ll,8888866666ll,8888866868ll,8888866886ll,8888868686ll,8888868866ll,8888868868ll,8888868886ll,8888886668ll,8888886686ll,8888886866ll,8888886868ll,8888886886ll,8888888666ll,8888888686ll,8888888866ll};
int cnt=943;
LL L,R,ans;
LL gcd(LL n,LL m){
return m?gcd(m,n%m):n;
}
void dfs(int dep,LL val,int tot){
if(dep==1){
if(tot==0)return ;
tot&1?ans+=(R/val-L/val):ans-=(R/val-L/val);return ;
}
LL tmp=val/gcd(a[dep-1],val)*a[dep-1];
dfs(dep-1,val,tot);
if(tmp<0||tmp>R)return ;
dfs(dep-1,tmp,tot+1);
}
int main(){
scanf("%lld%lld",&L,&R);
L--;
int pos=0;
dfs(cnt+1,1,0);
printf("%lld\n",ans);
}

(代码是1853,数据较强)

 

BZOJ_2393_Cirno的完美算数教室&&BZOJ_1853_[Scoi2010]幸运数字 _深搜+容斥原理的更多相关文章

  1. 【BZOJ1853/2393】[Scoi2010]幸运数字/Cirno的完美算数教室 DFS+容斥

    [BZOJ1853][Scoi2010]幸运数字 Description 在中国,很多人都把6和8视为是幸运数字!lxhgww也这样认为,于是他定义自己的“幸运号码”是十进制表示中只包含数字6和8的那 ...

  2. 【BZOJ-1853&2393】幸运数字&Cirno的完美算数教室 容斥原理 + 爆搜 + 剪枝

    1853: [Scoi2010]幸运数字 Time Limit: 2 Sec  Memory Limit: 64 MBSubmit: 1817  Solved: 665[Submit][Status] ...

  3. BZOJ2393: Cirno的完美算数教室

    2393: Cirno的完美算数教室 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 138  Solved: 83[Submit][Status] D ...

  4. 2393Cirno的完美算数教室 容斥

    2393: Cirno的完美算数教室 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 652  Solved: 389[Submit][Status][ ...

  5. Bzoj 2393: Cirno的完美算数教室 容斥原理,深搜

    2393: Cirno的完美算数教室 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 287  Solved: 175[Submit][Status][ ...

  6. ●BZOJ 2393 Cirno的完美算数教室

    题链: http://www.lydsy.com/JudgeOnline/problem.php?id=2393 题解: 容斥原理,暴力搜索,剪枝...和 [Scoi2010 幸运数字] 一样的(只是 ...

  7. Luogu P2567 [SCOI2010]幸运数字 容斥+脑子

    双倍经验:BZOJ 2393 Cirno的完美算数教室 做法:先把$[1,r]$中所有的幸运数字筛出来,然后用这些幸运数字来筛$[l,r]$中的近似幸运号码: 剪枝:当一个幸运数字$a[i]$是另一个 ...

  8. BZOJ 1853: [Scoi2010]幸运数字

    1853: [Scoi2010]幸运数字 Time Limit: 2 Sec  Memory Limit: 64 MBSubmit: 2117  Solved: 779[Submit][Status] ...

  9. Bzoj 1853: [Scoi2010]幸运数字 容斥原理,深搜

    1853: [Scoi2010]幸运数字 Time Limit: 2 Sec  Memory Limit: 64 MBSubmit: 1774  Solved: 644[Submit][Status] ...

随机推荐

  1. Course1-Python数据类型总结

    一. 开始正式学习前的tips: Python和其他语言有很多类似, 也有一些差异, 下面先总结了一些基本语法上的注意事项 1. 注意缩进 2. 一行语句分为多行显示: \ 3. 注释: 单行注释#, ...

  2. sqlite 数据类型 <转>

    一般数据采用的固定的静态数据类型,而SQLite采用的是动态数据类型,会根据存入值自动判断.SQLite具有以下五种数据类型: 1.NULL:空值.2.INTEGER:带符号的整型,具体取决有存入数字 ...

  3. java中文拼音字母排序

    package com.yputil.util; import java.text.CollationKey;import java.text.Collator;import java.util.Ar ...

  4. 微信小程序弹出和隐藏遮罩层动画以及五星评分

    参考源码: http://www.see-source.com/weixinwidget/detail.html?wid=82 https://blog.csdn.net/pcaxb/article/ ...

  5. Failed to create the Java Virtual Machine(zt)

    http://lixueli26.iteye.com/blog/711152 在以下版本也发生类似情况,采用同样方法得以解决. 版本:eclipse-jee-indigo-win32 自己电脑上装的j ...

  6. Ocelot中文文档-缓存

    目前Ocelot使用CacheManager项目提供了一些非常基本的缓存.这是一个了不起的项目,它解决了很多缓存问题. 我会推荐这个软件包来做Ocelot缓存. 如果你看看这里的例子,你可以看到如何设 ...

  7. 关于Elasticsearch 使用 MatchPhrase搜索的一些坑

    对分词字段检索使用的通常是match查询,对于短语查询使用的是matchphrase查询,但是并不是matchphrase可以直接对分词字段进行不分词检索(也就是业务经常说的精确匹配),下面有个例子, ...

  8. 拾人牙慧篇之——基于HTML5中websocket来实现消息推送功能

    一.写在前面 要求做一个,后台发布信息,前台能即时得到通知的消息推送功能.网上搜了也有很多方式,ajax的定时询问,Comet方式,Server-Sent方式,以及websocket.表示除了定时询问 ...

  9. MVC5 框架 配置 盘古分词

    2018.5.10日记 1.将sql数据库的内容添加到索引库中, public static readonly IndexManager instance; //静态构造函数,CLR只执行一次 sta ...

  10. Linux安装mysql(Redhat6.5+MySQL5.7)(转载+原创补漏)

    一.下载 这里我创建了一目录software用于存放我们待会要下载的mysql包,先去到该目录 命令:cd /software命令:wget http://mirrors.sohu.com/mysql ...