1853: [Scoi2010]幸运数字
Time Limit: 2 Sec Memory Limit: 64 MB
Submit: 1170 Solved: 406
[Submit][Status]
Description
在中国,很多人都把6和8视为是幸运数字!lxhgww也这样认为,于是他定义自己的“幸运号码”是十进制表示中只包含数字6和8的那些号码,比如68,666,888都是“幸运号码”!但是这种“幸运号码”总是太少了,比如在[1,100]的区间内就只有6个(6,8,66,68,86,88),于是他又定义了一种“近似幸运号码”。lxhgww规定,凡是“幸运号码”的倍数都是“近似幸运号码”,当然,任何的“幸运号码”也都是“近似幸运号码”,比如12,16,666都是“近似幸运号码”。 现在lxhgww想知道在一段闭区间[a, b]内,“近似幸运号码”的个数。
Input
输入数据是一行,包括2个数字a和b
Output
输出数据是一行,包括1个数字,表示在闭区间[a, b]内“近似幸运号码”的个数
Sample Input
【样例输入1】
1 10
【样例输入2】
1234 4321
Sample Output
【样例输出1】
2
【样例输出2】
809
HINT
【数据范围】
对于30%的数据,保证1 < =a < =b < =1000000
对于100%的数据,保证1 < =a < =b < =10000000000
搜索时数字从大到小。
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<vector> #include<cmath> #include<map> using namespace std; #define MAXN 10000000000LL #define MAXV 1000007 #define MAXE 10000000 #define INFL 0x3f3f3f3f3f3f3f3fLL typedef long long qword; qword num[943]=//{{{ {6ll,8ll,68ll,86ll,668ll,686ll,866ll,868ll,886ll,6668ll,6686ll,6866ll,6886ll,8666ll,8668ll,8866ll,66668ll,66686ll,66866ll,66868ll,66886ll,68666ll,68668ll,68686ll,68866ll,86666ll,86668ll,86686ll,86866ll,88868ll,88886ll,666668ll,666686ll,666866ll,666868ll,666886ll,668666ll,668686ll,668866ll,686666ll,686668ll,686866ll,688666ll,688868ll,688886ll,866666ll,866668ll,866686ll,868666ll,868886ll,886666ll,886868ll,888668ll,888686ll,888866ll,888868ll,888886ll,6666668ll,6666686ll,6666866ll,6666868ll,6668666ll,6668668ll,6668686ll,6668866ll,6686666ll,6686668ll,6686686ll,6686866ll,6688666ll,6688868ll,6688886ll,6866666ll,6866668ll,6866686ll,6866866ll,6868666ll,6868868ll,6868886ll,6886666ll,6886868ll,6886886ll,6888668ll,6888866ll,6888868ll,6888886ll,8666666ll,8666686ll,8666866ll,8668666ll,8668868ll,8686666ll,8686868ll,8686886ll,8688668ll,8688686ll,8688866ll,8688868ll,8688886ll,8866666ll,8866868ll,8866886ll,8868668ll,8868686ll,8868866ll,8868868ll,8868886ll,8886668ll,8886686ll,8886866ll,8886868ll,8886886ll,8888666ll,8888668ll,8888686ll,8888866ll,66666668ll,66666686ll,66666866ll,66666868ll,66666886ll,66668666ll,66668668ll,66668686ll,66668866ll,66686666ll,66686686ll,66686866ll,66688666ll,66688868ll,66688886ll,66866666ll,66866668ll,66866866ll,66868666ll,66868868ll,66886666ll,66886868ll,66886886ll,66888668ll,66888686ll,66888866ll,66888868ll,66888886ll,68666666ll,68666668ll,68666686ll,68668666ll,68668868ll,68668886ll,68686666ll,68686886ll,68688668ll,68688686ll,68688866ll,68688868ll,68688886ll,68866666ll,68866868ll,68868668ll,68868686ll,68868866ll,68868868ll,68886668ll,68886686ll,68886866ll,68886868ll,68886886ll,68888668ll,68888686ll,68888866ll,86666666ll,86666668ll,86666686ll,86666866ll,86668868ll,86668886ll,86686666ll,86686868ll,86686886ll,86688686ll,86688866ll,86688868ll,86688886ll,86866666ll,86866868ll,86866886ll,86868668ll,86868868ll,86868886ll,86886668ll,86886686ll,86886866ll,86886868ll,86886886ll,86888666ll,86888668ll,86888686ll,86888866ll,88666666ll,88666868ll,88666886ll,88668686ll,88668868ll,88668886ll,88686668ll,88686686ll,88686866ll,88686868ll,88686886ll,88688666ll,88688668ll,88688686ll,88688866ll,88866668ll,88866866ll,88866868ll,88866886ll,88868666ll,88868668ll,88868686ll,88868866ll,88886666ll,88886668ll,88886686ll,88886866ll,88888666ll,88888868ll,88888886ll,666666686ll,666666866ll,666666868ll,666666886ll,666668666ll,666668686ll,666668866ll,666686666ll,666686668ll,666686686ll,666686866ll,666688666ll,666688868ll,666688886ll,666866666ll,666866668ll,666866686ll,666866866ll,666868666ll,666868868ll,666868886ll,666886666ll,666886868ll,666886886ll,666888668ll,666888686ll,666888866ll,666888868ll,666888886ll,668666666ll,668666668ll,668666686ll,668666866ll,668668666ll,668668868ll,668668886ll,668686666ll,668686868ll,668686886ll,668688668ll,668688686ll,668688866ll,668688868ll,668688886ll,668866666ll,668866868ll,668866886ll,668868668ll,668868686ll,668868868ll,668868886ll,668886668ll,668886686ll,668886866ll,668886868ll,668886886ll,668888666ll,668888668ll,668888686ll,668888866ll,686666666ll,686666668ll,686666686ll,686666866ll,686668666ll,686668868ll,686668886ll,686686666ll,686686868ll,686686886ll,686688668ll,686688686ll,686688866ll,686688868ll,686688886ll,686866666ll,686866868ll,686866886ll,686868668ll,686868686ll,686868866ll,686868868ll,686868886ll,686886668ll,686886686ll,686886866ll,686886868ll,686886886ll,686888666ll,686888668ll,686888686ll,686888866ll,688666868ll,688666886ll,688668668ll,688668686ll,688668866ll,688668868ll,688668886ll,688686668ll,688686686ll,688686866ll,688686868ll,688686886ll,688688666ll,688688668ll,688688866ll,688866668ll,688866686ll,688866866ll,688866868ll,688866886ll,688868666ll,688868668ll,688868866ll,688886666ll,688886668ll,688886686ll,688886866ll,688888666ll,688888868ll,688888886ll,866666666ll,866666668ll,866666686ll,866666866ll,866668666ll,866668868ll,866668886ll,866686666ll,866686868ll,866686886ll,866688668ll,866688686ll,866688866ll,866688868ll,866688886ll,866866666ll,866866868ll,866866886ll,866868668ll,866868686ll,866868866ll,866868868ll,866868886ll,866886668ll,866886686ll,866886866ll,866886868ll,866886886ll,866888666ll,866888668ll,866888866ll,868666666ll,868666868ll,868666886ll,868668668ll,868668686ll,868668866ll,868668868ll,868686668ll,868686686ll,868686866ll,868686868ll,868686886ll,868688668ll,868688686ll,868688866ll,868866866ll,868866868ll,868866886ll,868868666ll,868868668ll,868868686ll,868868866ll,868886666ll,868886668ll,868886686ll,868886866ll,868888666ll,868888868ll,868888886ll,886666666ll,886666868ll,886666886ll,886668668ll,886668866ll,886668868ll,886668886ll,886686668ll,886686686ll,886686866ll,886686868ll,886686886ll,886688666ll,886688668ll,886688686ll,886688866ll,886866668ll,886866686ll,886866866ll,886866868ll,886866886ll,886868666ll,886868668ll,886868686ll,886868866ll,886886666ll,886886686ll,886886866ll,886888666ll,886888868ll,886888886ll,888666668ll,888666686ll,888666866ll,888666868ll,888666886ll,888668666ll,888668668ll,888668686ll,888668866ll,888686666ll,888686668ll,888686686ll,888686866ll,888688666ll,888688868ll,888688886ll,888866666ll,888866668ll,888866686ll,888866866ll,888868666ll,888868886ll,888886666ll,888886868ll,888886886ll,888888668ll,888888686ll,888888866ll,888888868ll,888888886ll,6666666668ll,6666666686ll,6666666866ll,6666666868ll,6666666886ll,6666668666ll,6666668668ll,6666668686ll,6666668866ll,6666686666ll,6666686668ll,6666686686ll,6666686866ll,6666688666ll,6666688886ll,6666866666ll,6666866686ll,6666866866ll,6666868666ll,6666868868ll,6666868886ll,6666886666ll,6666886868ll,6666886886ll,6666888668ll,6666888686ll,6666888866ll,6666888868ll,6666888886ll,6668666666ll,6668666668ll,6668666866ll,6668668666ll,6668668868ll,6668668886ll,6668686666ll,6668686868ll,6668686886ll,6668688686ll,6668688866ll,6668688868ll,6668688886ll,6668866666ll,6668866868ll,6668866886ll,6668868668ll,6668868686ll,6668868866ll,6668868886ll,6668886668ll,6668886686ll,6668886866ll,6668886868ll,6668886886ll,6668888666ll,6668888668ll,6668888686ll,6668888866ll,6686666666ll,6686666686ll,6686668666ll,6686668868ll,6686668886ll,6686686666ll,6686686868ll,6686686886ll,6686688668ll,6686688686ll,6686688866ll,6686688868ll,6686688886ll,6686866666ll,6686866886ll,6686868668ll,6686868686ll,6686868866ll,6686868868ll,6686868886ll,6686886668ll,6686886686ll,6686886866ll,6686886868ll,6686886886ll,6686888666ll,6686888668ll,6686888686ll,6686888866ll,6688666666ll,6688666868ll,6688668668ll,6688668686ll,6688668866ll,6688668868ll,6688668886ll,6688686668ll,6688686686ll,6688686866ll,6688686868ll,6688686886ll,6688688666ll,6688688668ll,6688688686ll,6688688866ll,6688866668ll,6688866686ll,6688866866ll,6688866868ll,6688866886ll,6688868666ll,6688868668ll,6688868686ll,6688868866ll,6688886666ll,6688886668ll,6688886686ll,6688886866ll,6688888666ll,6688888868ll,6688888886ll,6866666666ll,6866666668ll,6866666686ll,6866666866ll,6866668868ll,6866668886ll,6866686666ll,6866686868ll,6866686886ll,6866688668ll,6866688866ll,6866688868ll,6866688886ll,6866866666ll,6866866868ll,6866866886ll,6866868686ll,6866868866ll,6866868868ll,6866868886ll,6866886668ll,6866886686ll,6866886866ll,6866886868ll,6866886886ll,6866888666ll,6866888668ll,6866888686ll,6866888866ll,6868666666ll,6868666868ll,6868666886ll,6868668668ll,6868668866ll,6868668868ll,6868668886ll,6868686668ll,6868686686ll,6868686866ll,6868686886ll,6868688666ll,6868688668ll,6868688686ll,6868688866ll,6868866668ll,6868866686ll,6868866866ll,6868866868ll,6868866886ll,6868868666ll,6868868668ll,6868868686ll,6868868866ll,6868886666ll,6868886668ll,6868886686ll,6868886866ll,6868888666ll,6868888868ll,6886666666ll,6886666868ll,6886666886ll,6886668668ll,6886668686ll,6886668868ll,6886668886ll,6886686668ll,6886686686ll,6886686866ll,6886686868ll,6886686886ll,6886688666ll,6886688668ll,6886688686ll,6886688866ll,6886866686ll,6886866866ll,6886866868ll,6886866886ll,6886868666ll,6886868668ll,6886868686ll,6886868866ll,6886886666ll,6886886668ll,6886886686ll,6886886866ll,6886888666ll,6886888868ll,6886888886ll,6888666668ll,6888666686ll,6888666866ll,6888666868ll,6888666886ll,6888668666ll,6888668686ll,6888668866ll,6888686666ll,6888686668ll,6888686686ll,6888686866ll,6888688868ll,6888688886ll,6888866666ll,6888866668ll,6888866866ll,6888868666ll,6888868868ll,6888868886ll,6888886666ll,6888886868ll,6888886886ll,6888888668ll,6888888686ll,6888888866ll,6888888868ll,6888888886ll,8666666666ll,8666666668ll,8666666686ll,8666666866ll,8666668666ll,8666668868ll,8666668886ll,8666686868ll,8666686886ll,8666688668ll,8666688686ll,8666688866ll,8666688868ll,8666688886ll,8666866666ll,8666866868ll,8666866886ll,8666868686ll,8666868866ll,8666868868ll,8666868886ll,8666886686ll,8666886866ll,8666886868ll,8666886886ll,8666888666ll,8666888668ll,8666888686ll,8666888866ll,8668666666ll,8668666868ll,8668666886ll,8668668668ll,8668668686ll,8668668866ll,8668668868ll,8668668886ll,8668686668ll,8668686866ll,8668686868ll,8668686886ll,8668688666ll,8668688668ll,8668688686ll,8668688866ll,8668866668ll,8668866686ll,8668866866ll,8668866868ll,8668866886ll,8668868666ll,8668868668ll,8668868686ll,8668868866ll,8668886666ll,8668886668ll,8668886686ll,8668886866ll,8668888868ll,8668888886ll,8686666666ll,8686666886ll,8686668668ll,8686668686ll,8686668866ll,8686668868ll,8686668886ll,8686686668ll,8686686686ll,8686686868ll,8686686886ll,8686688666ll,8686688668ll,8686688686ll,8686688866ll,8686866668ll,8686866686ll,8686866866ll,8686866868ll,8686866886ll,8686868666ll,8686868668ll,8686868866ll,8686886666ll,8686886668ll,8686886686ll,8686886866ll,8686888666ll,8686888868ll,8686888886ll,8688666668ll,8688666686ll,8688666866ll,8688666868ll,8688666886ll,8688668668ll,8688668686ll,8688668866ll,8688686666ll,8688686668ll,8688686686ll,8688686866ll,8688688666ll,8688688868ll,8688688886ll,8688866666ll,8688866686ll,8688866866ll,8688868666ll,8688868868ll,8688868886ll,8688886666ll,8688886868ll,8688886886ll,8688888668ll,8688888686ll,8688888866ll,8688888868ll,8688888886ll,8866666666ll,8866666868ll,8866666886ll,8866668668ll,8866668686ll,8866668866ll,8866668868ll,8866686686ll,8866686866ll,8866686868ll,8866686886ll,8866688668ll,8866688686ll,8866688866ll,8866866668ll,8866866866ll,8866866886ll,8866868666ll,8866868668ll,8866868686ll,8866868866ll,8866886666ll,8866886668ll,8866886686ll,8866886866ll,8866888666ll,8866888868ll,8866888886ll,8868666668ll,8868666686ll,8868666866ll,8868666868ll,8868666886ll,8868668668ll,8868668686ll,8868668866ll,8868686666ll,8868686668ll,8868686686ll,8868686866ll,8868688666ll,8868688868ll,8868688886ll,8868866666ll,8868866668ll,8868866686ll,8868866866ll,8868868666ll,8868868868ll,8868868886ll,8868886666ll,8868886868ll,8868886886ll,8868888668ll,8868888686ll,8868888866ll,8868888868ll,8868888886ll,8886666668ll,8886666686ll,8886666866ll,8886666868ll,8886666886ll,8886668666ll,8886668668ll,8886668686ll,8886668866ll,8886686666ll,8886686668ll,8886686686ll,8886686866ll,8886688666ll,8886688886ll,8886866666ll,8886866668ll,8886866686ll,8886866866ll,8886868666ll,8886868868ll,8886868886ll,8886886666ll,8886886868ll,8886886886ll,8886888686ll,8886888866ll,8886888886ll,8888666666ll,8888666668ll,8888666686ll,8888666866ll,8888668666ll,8888668868ll,8888668886ll,8888686666ll,8888686868ll,8888686886ll,8888688668ll,8888688686ll,8888688866ll,8888688868ll,8888866666ll,8888866868ll,8888866886ll,8888868686ll,8888868866ll,8888868868ll,8888868886ll,8888886668ll,8888886686ll,8888886866ll,8888886868ll,8888886886ll,8888888666ll,8888888686ll,8888888866ll};//}}} int topn=942; vector<qword> vec; qword n,ans; qword gcd(qword x,qword y) { return (x%y)?gcd(y,x%y):y; } qword lcm(qword x,qword y) { qword a=gcd(x,y); if (x/100*y/100/a>n/10000)return INFL; return x*y/a; } qword search_m(int now,int tot,qword v) { qword ret=0; if (now==943) { if (v==1)return 0; ret=(tot%2?1:-1)*(n/v); return ret; } ret+=search_m(now+1,tot,v); qword t=lcm(num[now],v); if (t<=n) { ret+=search_m(now+1,tot^1,t); } return ret; } int main() { //freopen("input.txt","r",stdin); qword i,j,k,x,y; bool flag=true; qword l,r; scanf("%lld%lld",&l,&r); for (i=0;i<943/2;i++) swap(num[i],num[943-i-1]); n=l-1; ans-=search_m(0,0,1); n=r; ans+=search_m(0,0,1); cout<<ans<<endl; /* for (i=1;i<MAXN;i++) { x=i; y=1; flag=true; while (x) { while (x%10!=6 && x%10!=8) { i+=y;x++; } x/=10; y*=10; } if (flag) { for (j=0;j<vec.size();j++) { if (i%vec[j]==0) { flag=false; break; } } if (!flag)continue; cout<<i<<"ll,"; vec.push_back(i); } }*/ }
时间: 2024-10-19 02:44:46