2393: Cirno的完美算数教室
Time Limit: 10 Sec Memory Limit: 128 MB
Submit: 138 Solved: 83
[Submit][Status]
Description
~Cirno发现了一种baka数,这种数呢~只含有2和⑨两种数字~~
现在Cirno想知道~一个区间中~~有多少个数能被baka数整除~
但是Cirno这么天才的妖精才不屑去数啦
只能依靠聪明的你咯。
Input
一行正整数L R
( 1 < L < R < 10^10)
Output
一个正整数,代表所求的答案
Sample Input
1 100
Sample Output
58
HINT
题解:
同幸运数字,第一次排rank1,哈哈!
代码:
#include<cstdio> #include<cstdlib> #include<cmath> #include<cstring> #include<algorithm> #include<iostream> #include<vector> #include<map> #include<set> #include<queue> #include<string> #define inf 1000000000 #define maxn 1200 #define maxm 500+100 #define eps 1e-10 #define ll unsigned long long #define pa pair<int,int> #define for0(i,n) for(int i=0;i<=(n);i++) #define for1(i,n) for(int i=1;i<=(n);i++) #define for2(i,x,y) for(int i=(x);i<=(y);i++) #define for3(i,x,y) for(int i=(x);i>=(y);i--) #define mod 1000000007 using namespace std; inline ll read() { ll x=,f=;char ch=getchar(); while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();} while(ch>=''&&ch<=''){x=*x+ch-'';ch=getchar();} return x*f; }
ll l,r,ans,tot,n,a[maxn],b[maxn];
ll v[maxn];
inline void dfs(ll x)
{
if(x>r)return;
if(x)a[++tot]=x;
dfs(*x+);
dfs(*x+);
}
inline ll gcd(ll x,ll y)
{
return y?gcd(y,x%y):x;
}
inline void calc(ll x,int y,int z)
{
if(y>n)
{
if(z&)ans+=r/x-(l-)/x;
else if(z)ans-=r/x-(l-)/x;
return;
}
calc(x,y+,z);
ll t=(x/gcd(x,a[y]))*a[y];
if(t<=r)calc(t,y+,z+);
} int main() { freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); l=read();r=read();
dfs();
sort(a+,a+tot+);
for1(i,tot)
if(!v[i])
{
b[++n]=a[i];
for2(j,i+,tot)if(a[j]%a[i]==)v[j]=;
}
for1(i,n)a[n+-i]=b[i];
calc(,,);
printf("%lld\n",ans); return ; }