poj 3909 简单 搜索
2012-09-18 10:25
260 查看
Lucky numbers
Description
John has recently arrived in Bucharest for the South Eastern European Regional Contest. John is famous for his theory of lucky numbers. That’s why all the contestants and spectators are very happy.
According to that theory 4 and 7 are lucky digits, and all the other digits are not lucky. A lucky number is a number that contains only lucky digits in decimal notation. A very lucky number is a number that can be expressed as a product of several lucky numbers.
A lucky number by itself is considered to be very lucky. For example, numbers 47, 49, 112 are very lucky.
Your task is to calculate the number of very lucky numbers that are not less than A and not greater than B. Of course, numbers A and B are given by John.
Input
The first line of the input contains a single integer T – a number of test cases. Each of the next T lines contains two integers separated by a single space – A and B.
Output
Output must contain T lines – answers for the test cases.
Sample Input
Sample Output
Hint
Constrains:
1 ≤ T ≤ 7777,
1 ≤ A ≤ B ≤ 1000000000000 (1012).
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 510 | Accepted: 172 |
John has recently arrived in Bucharest for the South Eastern European Regional Contest. John is famous for his theory of lucky numbers. That’s why all the contestants and spectators are very happy.
According to that theory 4 and 7 are lucky digits, and all the other digits are not lucky. A lucky number is a number that contains only lucky digits in decimal notation. A very lucky number is a number that can be expressed as a product of several lucky numbers.
A lucky number by itself is considered to be very lucky. For example, numbers 47, 49, 112 are very lucky.
Your task is to calculate the number of very lucky numbers that are not less than A and not greater than B. Of course, numbers A and B are given by John.
Input
The first line of the input contains a single integer T – a number of test cases. Each of the next T lines contains two integers separated by a single space – A and B.
Output
Output must contain T lines – answers for the test cases.
Sample Input
4 1 2 88 99 112 112 1 100
Sample Output
0 0 1 10
Hint
Constrains:
1 ≤ T ≤ 7777,
1 ≤ A ≤ B ≤ 1000000000000 (1012).
#include<iostream> #include<algorithm> #include<cstdio> using namespace std; const __int64 inf=1000000000000LL; const int maxn=10002; const int maxm=50000000; int t,l,ll; __int64 d[maxn],s[maxm],a,b; void dfs(__int64 p,int step) { if(step>12) return; d[l++]=p*10+4; d[l++]=p*10+7; dfs(p*10+4,step+1); dfs(p*10+7,step+1); } void dfs1(__int64 p,int step) { if(step>=l)return; if(d[step]>inf/p) return; dfs1(p,step+1); while(d[step]<=inf/p) { p*=d[step]; s[ll++]=p; dfs1(p,step+1); } } int main() { l=0,s[ll=1]=0; dfs(0,1); sort(d,d+l); dfs1(1,0); sort(s,s+ll); int len=unique(s,s+ll)-s; // cout<<"OK "<<l<<" "<<ll<<endl; scanf("%d",&t); while(t--) { scanf("%I64d%I64d",&a,&b); int id1=upper_bound(s,s+len,a-1)-s; int id2=upper_bound(s,s+len,b)-s; printf("%d\n",id2-id1); } return 0; }
相关文章推荐
- [kuangbin带你飞]专题一 简单搜索D - Fliptile(POJ 3279)
- POJ 1321 棋盘问题(DFS板子题,简单搜索练习)
- Network Saboteur poj 2531 dfs 简单搜索技巧和剪枝
- [kuangbin带你飞]专题一 简单搜索 A - 棋盘问题(POJ 1321)
- [kuangbin带你飞]专题一 简单搜索D - Fliptile(POJ 3279)
- poj2386——油田问题(简单搜索)
- [kuangbin带你飞]专题一 简单搜索-C - Catch That Cow POJ - 3278
- poj 3278 简单的搜索
- POJ - 3984 迷宫问题 [kuangbin带你飞]专题一 简单搜索
- POJ 2488 A Knight's Journey(简单搜索)
- 【简单搜索】POJ1321棋盘问题
- poj 1033 Defragment 简单搜索
- [kuangbin带你飞]专题1 简单搜索 H - Pots POJ - 3414
- poj 2488 简单的搜索
- poj 3126 Prime Path([kuangbin带你飞]专题一 简单搜索)
- poj1426 Find The Multiple 简单搜索
- POJ 1321棋盘问题(简单搜索dfs回溯)
- [kuangbin带你飞]专题一 简单搜索E - Find The Multiple(POJ 1426)
- POJ-3279(Fliptile)--简单搜索
- POJ 1321棋盘问题(简单搜索)