Bzoj1853: [scoi2010] Lucky number

Source: Internet
Author: User
1853: [scoi2010] Lucky number time limit: 2 sec memory limit: 64 MB
Submit: 1129 solved: 392
[Submit] [Status] Description in China, many people regard "6" and "8" as lucky numbers! Lxhgww thinks so, so he defines his "lucky number" as a decimal number that only contains numbers 6 and 8. For example, 68,666,888 is a "lucky number "! However, this "lucky number" is always too small. For example, there are only 6 (1,100,) in the range ), so he defined a similar lucky number ". Lxhgww stipulates that all the multiples of "Lucky Numbers" are "approximate lucky numbers". Of course, any "Lucky Numbers" are also "approximate lucky numbers", such as 12, 16, 666 is an approximate lucky number ". Lxhgww wants to know the number of "approximate lucky numbers" in a closed range [a, B. The input data is a row, including two numbers a and boutput. The output data is a row, including one number, indicating that the data is in the closed range [, b] Number of "approximate lucky numbers" in sample input [Example input 1]
1 10
[Example input 2]
1234 4321
Sample output [sample output 1]
2
[Sample output 2]
809
Hint

[Data Scope]
For 30% of data, ensure 1 <= A <= B <= 1000000
For 100% of data, ensure 1 <= A <= B <= 10000000000

Source

Day1

Question:

It seems so difficult, but now it looks so simple... But why T chengxiang... I have no choice but to read the question...

Http://z55250825.blog.163.com/blog/static/150230809201432103111474/

His blog is very clear...

The last optimization seems to be possible only by changing to the unsigned LL. I see the code 23333 of lyd.

Code:

  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 5000 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+6); 67     dfs(10*x+8); 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

 

Bzoj1853: [scoi2010] Lucky number

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.