bzoj 1853 幸运数字
2015-11-16 10:38
246 查看
!x是x==0的意思!!!预处理出只含86的数字,利用容斥原理求解。
#include<cstdio> #include<cstdlib> #include<cstring> #include<algorithm> #include<cmath> #define md #define ll long long #define inf (int) 1e9 #define eps 1e-8 #define N 1000100 using namespace std; ll q ; bool tag ; ll L,R,ans=0; int w=0; bool cmp(ll a,ll b) {return a>b;} ll gcd (ll a,ll b) { return b==0?a:gcd(b,a%b);} void dfs_86(ll x) { if (x>R) return; if (x) q[++w]=x; dfs_86(x*10+6); dfs_86(x*10+8); } void dfs(int pos,int dep,ll lcm) { if (pos>w) return; dfs(pos+1,dep,lcm); if (tag[pos]) return; lcm*=(q[pos]/gcd(lcm,q[pos])); if ((lcm<=0)||lcm>R) return; dep++; if (dep&1) ans+=R/lcm-(L-1)/lcm; else ans-=R/lcm-(L-1)/lcm; dfs(pos+1,dep,lcm); } int main() { scanf("%lld%lld",&L,&R); dfs_86(0); sort(q+1,q+w+1,cmp); for (int i=1;i<=w;i++) for (int j=i+1;j<=w;j++) if (q[i]%q[j]==0) { tag[i]=1; break;} dfs(1,0,1); printf("%lld\n",ans); return 0; }
相关文章推荐
- bzoj 3620 似乎在梦中见过的样子
- bzoj 3916 friends | 字符串hash
- bzoj 1047 理想的正方形
- bzoj 3918 postman
- bzoj 3098 hash killer
- bzoj 1875 HH去散步
- bzoj 3679 数字之积
- bzoj 屯题计划 完结
- bzoj 3503 和谐矩阵
- bzoj 2242 计算器
- bzoj 2597 石头剪刀布
- bzoj 3532 lis
- bzoj 3130 费用流
- bzoj 1500 维修数列 bzoj 1507 editor
- bzoj 1251 序列终结者
- bzoj 4152 the camptin (dis[x][y]=min(|x.x-y.x|,|x.y-y.y|),求1,n最短路)
- bzoj 3029 守卫者的挑战
- bzoj 2118 墨墨的等式
- <android5.0>之曲线动画(Curved motion(曲线运动))
- 浅谈虚数i在电路分析中的作用