题意:求闭区间内能被6和8组成的数字整除的数目。n<=1e11.

我们可以预处理出这些6和8组成的数字,大概2500个,然后排除一些如88,66的情况。这样大概还剩下1000个。

转化为[0,r]和[0,l-1]的问题,显然需要运用容斥原理。ans=n/6+n/8+n/68+...+...-n/lcm(6,8)-n/lcm(6,68)......

因此用dfs即可计算出来,这样一看复杂度好像是2^1000的样子,但是注意到lcm增长的很快,如果lcm>n那么显然之后的这些情况就可以忽略了。

这就是一个强有力的剪枝。

另外从大到小dfs要比从小到大dfs要好。大概常数小?

# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iostream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <set>
# include <cmath>
# include <algorithm>
using namespace std;
# define lowbit(x) ((x)&(-x))
# define pi acos(-1.0)
# define eps 1e-
# define MOD
# define INF
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
# define FO(i,a,n) for(int i=a; i<n; ++i)
# define bug puts("H");
# define lch p<<,l,mid
# define rch p<<|,mid+,r
# define mp make_pair
# define pb push_back
typedef pair<int,int> PII;
typedef vector<int> VI;
# pragma comment(linker, "/STACK:1024000000,1024000000")
typedef long long LL;
int Scan() {
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
void Out(int a) {
if(a<) {putchar('-'); a=-a;}
if(a>=) Out(a/);
putchar(a%+'');
}
const int N=;
//Code begin... LL num[], pos1, pos2, p[], mark[];
void init(){
p[]=; FOR(i,,) p[i]=p[i-]*;
int l=, r=, tmpl, tmpr;
num[++pos1]=; num[++pos1]=;
FOR(i,,) {
tmpl=r+;
FOR(j,l,r) num[++pos1]=*p[i-]+num[j];
FOR(j,l,r) num[++pos1]=*p[i-]+num[j];
tmpr=pos1;
l=tmpl; r=tmpr;
}
FOR(i,,pos1) {
int flag=true;
FO(j,,i) if (num[i]%num[j]==) {flag=false; break;}
if (flag) mark[++pos2]=num[i];
}
mark[++pos2]=1e16;
}
LL dfs(int pos, int flag, LL x, LL cheng){
if (pos<=) return ;
LL res=;
res+=dfs(pos-,flag,x,cheng);
LL tmp=__gcd(cheng,mark[pos]);
if (cheng/tmp<=(double)x/mark[pos]) {
LL tt=cheng/tmp*mark[pos];
res+=dfs(pos-,flag^,x,tt);
res+=(flag?x/tt:-x/tt);
}
return res;
}
LL sol(LL x){
for (int i=pos2; i>=; --i) if (mark[i]<=x) return dfs(i,,x,);
return ;
}
int main ()
{
init();
LL a, b;
scanf("%lld%lld",&a,&b);
printf("%lld\n",sol(b)-sol(a-));
return ;
}

最新文章

  1. 利用pixi.js制作精灵动画
  2. js获取url参数值,js获取其他页面传递而来的值
  3. Archlinux添加MP3播放器
  4. AX7 VM can not starting
  5. 扩展KMP题目
  6. vs目录(继承的值)配置
  7. hdu 1010 Tempter of the Bone 深搜+剪枝
  8. Mantis 1.1.0 报告问题中设置必填项或取消必填项[Z]
  9. HTML与XML关系分析
  10. c#入门基础笔记
  11. js常用正则表达式表单验证代码
  12. [开发技巧]&#183;Numpy中对axis的理解与应用
  13. element-ui中上传文件upload
  14. Linux用户抢占和内核抢占详解(概念, 实现和触发时机)--Linux进程的管理与调度(二十)
  15. Java 雇员管理小练习(理解面向对象编程)
  16. finecms如何控制调用子栏目的数量
  17. EF-获取自增ID值
  18. scrapy之parallel
  19. &lt;跟股市谚语学炒股&gt; 读书笔记
  20. log4net配置详细说明

热门文章

  1. Linux 下 的 Oracle,如何安装 tnsname
  2. Objective-C 方法交换实践(一) - 基础知识
  3. JS基础,课堂作业,成绩练习
  4. Selenium2+python自动化-操作浏览器基本方法
  5. 面试时让你说一个印象最深的bug,该怎么回答
  6. NO.05--谈一谈Angular 和 Vue.js 的对比。
  7. ERROR [IM002] [Microsoft][ODBC 驱动程序管理器] 未发现数据源名称并且未指定默认驱动程序
  8. php异步学习(2)
  9. Spring演示及总结
  10. 针对某一网站的UI进行分析