题意
~Cirno发现了一种baka数,这种数呢~只含有2和⑨两种数字~~
现在Cirno想知道~一个区间中~~有多少个数能被baka数整除~
但是Cirno这么天才的妖精才不屑去数啦
只能依靠聪明的你咯。
题解
看题面猜到做法系列。。
肯定有结论,要么互质的特别多,要么是倍数的比较多。。
然后打个表
发现没什么互质的
但是删去倍数的的,剩下460+个。。
然后再猜,乘积很快就会爆
1010
10
10
暴力容斥没问题
表都懒得打。。直接上代码。。
于是1A了。。
CODE:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
typedef long long LL;
LL a[2000];
LL l,r;
void dfs (LL x,LL y)
{
if (y>r) return ;
a[++a[0]]=y;
dfs(x+1,y*10+2);
dfs(x+1,y*10+9);
}
LL gcd (LL x,LL y)
{
if (x==0) return y;
return gcd(y%x,x);
}
bool vis[2005];
LL tot=1;
LL ans=0;
void dfs (LL x,LL o,LL now)
{
// printf("%lld %lld %lld\n",x,o,now);
if (x>tot)
{
if (o%2==1)
ans=ans+r/now-(l-1)/now;
else
ans=ans-r/now+(l-1)/now;
return ;
}
dfs(x+1,o,now);
LL tt=now/gcd(now,a[x])*a[x];
if (tt>r) return ;
dfs(x+1,o+1,tt);
}
int main()
{
memset(vis,true,sizeof(vis));
scanf("%lld%lld",&l,&r);
dfs(1,2);dfs(1,9);
LL sum=0;
for (LL u=1;u<=a[0];u++)
for (LL i=u+1;i<=a[0];i++)
if (a[i]%a[u]==0)
vis[i]=false;
for (LL u=2;u<=a[0];u++)
if (vis[u])
a[++tot]=a[u];
/*for (LL u=1;u<=tot;u++)
printf("%lld ",a[u]);
printf("\n");*/
dfs(1,1,1);
printf("%lld\n",(r-l+1)-ans);
return 0;
}