双倍经验:BZOJ 2393 Cirno的完美算数教室


做法:先把$[1,r]$中所有的幸运数字筛出来,然后用这些幸运数字来筛$[l,r]$中的近似幸运号码;

剪枝:当一个幸运数字$a[i]$是另一个幸运数字$a[j]$的倍数时,那么应该把$a[i]$去掉;

贡献用容斥搞一下好了(就是dfs部分)。。

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cctype>
#include<cstdlib>
#include<vector>
#include<map>
#include<set>
#define ll long long
#define R register ll
static char B[<<],*S=B,*D=B;
#define getchar() (S==D&&(D=(S=B)+fread(B,1,1<<15,stdin),S==D)?EOF:*S++)
using namespace std;
inline ll g() {
R ret=,fix=; register char ch; while(!isdigit(ch=getchar())) fix=ch=='-'?-:fix;
do ret=ret*+(ch^); while(isdigit(ch=getchar())); return ret*fix;
} ll q[],l,r,ans; bool vis[]; int tot;
inline void PRE(ll x) {if(x>r) return ; if(x) q[++tot]=x; PRE(x*+); PRE(x*+);}
inline ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
inline bool cmp(const ll& a,const ll& b) {return a>b;}
inline void dfs(int x,int d,ll L) {
if(x==tot) return ; ++x; dfs(x,d,L); d^=;
if(vis[x]) return ; L=L*q[x]/gcd(L,q[x]);
if(L<=||L>r) return ; if(d) ans+=r/L-(l-)/L;
else ans-=r/L-(l-)/L; dfs(x,d,L);
}
signed main() {
l=g(),r=g(); PRE(); sort(q+,q+tot+,cmp);
for(R i=;i<=tot;++i) for(R j=i+;j<=tot;++j) if(q[i]%q[j]==) {vis[i]=; break; }
dfs(,,); printf("%lld\n",ans);
}

2019.06.04别颓。

最新文章

  1. Oracle update和order by
  2. SQL Server 数据缓存
  3. 【译】Java中的对象序列化
  4. UWP开发入门(十四)—— UserControl中Adaptive UI的小技巧
  5. Button控件常用api
  6. WCF学习
  7. [备忘]Visio中连接线交叉时跨线小弯的去掉方法
  8. Maven依赖(转)
  9. 黑马程序员——有关protocol的小结
  10. asp:保留两位小数:
  11. CSS 设计彻底研究(四)盒子的浮动与定位
  12. sublime3下载安装及常用插件
  13. [CF337D]邪恶古籍-树状dp
  14. .Net Core配置文件介绍
  15. .net core Kestrel宿主服务器自定义监听端口配置
  16. nmap的使用
  17. python base64加解密
  18. 20165228 2017-2018-2 《Java程序设计》第4周学习总结
  19. c#day05
  20. HTTP响应状态码

热门文章

  1. (MVC — — Demo)客户管理系统的开发日志
  2. C++目录
  3. Pycharm 配置houdini
  4. 移动端测试之APP安全测试
  5. CF网络流练习
  6. Python字符串常用的方法——真心觉得比java,c好用
  7. svg使用
  8. 初学java3 条件判断
  9. javaIO——BufferedReader
  10. 【atcoder】Enclosed Points [abc136F]