首页 > 代码库 > BZOJ2393: Cirno的完美算数教室

BZOJ2393: Cirno的完美算数教室

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,哈哈!

代码:

  1 #include<cstdio>  2   3 #include<cstdlib>  4   5 #include<cmath>  6   7 #include<cstring>  8   9 #include<algorithm> 10  11 #include<iostream> 12  13 #include<vector> 14  15 #include<map> 16  17 #include<set> 18  19 #include<queue> 20  21 #include<string> 22  23 #define inf 1000000000 24  25 #define maxn 1200 26  27 #define maxm 500+100 28  29 #define eps 1e-10 30  31 #define ll unsigned long long 32  33 #define pa pair<int,int> 34  35 #define for0(i,n) for(int i=0;i<=(n);i++) 36  37 #define for1(i,n) for(int i=1;i<=(n);i++) 38  39 #define for2(i,x,y) for(int i=(x);i<=(y);i++) 40  41 #define for3(i,x,y) for(int i=(x);i>=(y);i--) 42  43 #define mod 1000000007 44  45 using namespace std; 46  47 inline ll read() 48  49 { 50  51     ll x=0,f=1;char ch=getchar(); 52  53     while(ch<0||ch>9){if(ch==-)f=-1;ch=getchar();} 54  55     while(ch>=0&&ch<=9){x=10*x+ch-0;ch=getchar();} 56  57     return x*f; 58  59 } 60 ll l,r,ans,tot,n,a[maxn],b[maxn]; 61 ll v[maxn]; 62 inline void dfs(ll x) 63 { 64     if(x>r)return; 65     if(x)a[++tot]=x; 66     dfs(10*x+2); 67     dfs(10*x+9); 68 }     69 inline ll gcd(ll x,ll y) 70 { 71     return y?gcd(y,x%y):x; 72 } 73 inline void calc(ll x,int y,int z) 74 { 75     if(y>n) 76     { 77             if(z&1)ans+=r/x-(l-1)/x; 78             else if(z)ans-=r/x-(l-1)/x; 79             return;     80     } 81     calc(x,y+1,z); 82     ll t=(x/gcd(x,a[y]))*a[y]; 83     if(t<=r)calc(t,y+1,z+1); 84 }     85  86 int main() 87  88 { 89  90     freopen("input.txt","r",stdin); 91  92     freopen("output.txt","w",stdout); 93  94     l=read();r=read(); 95     dfs(0); 96     sort(a+1,a+tot+1); 97     for1(i,tot) 98     if(!v[i]) 99     {100         b[++n]=a[i];101         for2(j,i+1,tot)if(a[j]%a[i]==0)v[j]=1;102     }103     for1(i,n)a[n+1-i]=b[i];104     calc(1,1,0);105     printf("%lld\n",ans);106 107     return 0;108 109 }
View Code

 

BZOJ2393: Cirno的完美算数教室