1276 - Very Lucky Numbers
| Time Limit: 3 second(s) | Memory Limit: 32 MB |
According to some 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.
Input
Input starts with an integer T (≤ 8000), denoting the number of test cases.
Each case starts with a line containing two integers A and B (1 ≤ A ≤ B ≤ 1012).
Output
For each case, print the case number and the result.
Sample Input |
Output for Sample Input |
|
4 1 2 88 99 112 112 1 100 |
Case 1: 0 Case 2: 0 Case 3: 1 Case 4: 10 |
Note
Very lucky numbers for the last sample input are 4, 7, 16, 28, 44, 47, 49, 64, 74 and 77.
题意:只由4和7构成的数是幸运数,然后由这些数数构成的数是非常幸运数字,然后问你在某个区间里有多少个这样的数;
思路:先dfs打表出幸运数字,然后再dfs打出非常幸运数字,dfs时用map去重,最后二分求解。
1 #include<stdio.h>
2 #include<algorithm>
3 #include<iostream>
4 #include<string.h>
5 #include<queue>
6 #include<stdlib.h>
7 #include<math.h>
8 #include<stack>
9 #include<vector>
10 #include<map>
11 using namespace std;
12 typedef long long LL;
13 map<LL,int>my;
14 LL ans[10000];
15 LL bns[1000000];
16 int N;
17 int M;
18 void dfs1(LL u,int k);
19 void dfs(int n,int m,LL u);
20 int main(void)
21 {
22 int i,j,k;
23 N=0;
24 M=0;
25 dfs(0,12,0);
26 sort(ans,ans+N);
27 dfs1(1,0);
28 sort(bns,bns+M);
29 scanf("%d",&k);
30 int s;
31 LL n,m;
32 for(s=1; s<=k; s++)
33 {
34 scanf("%lld %lld",&n,&m);
35 n-=1;
36 int l=0;
37 int r=M-1;
38 int id=-1;
39 while(l<=r)
40 {
41 int mid=(l+r)/2;
42 if(bns[mid]<=n)
43 {
44 id=mid;
45 l=mid+1;
46 }
47 else r=mid-1;
48 }
49 int ic=-1;
50 l=0;
51 r=M-1;
52 while(l<=r)
53 {
54 int mid=(l+r)/2;
55 if(bns[mid]<=m)
56 {
57 ic=mid;
58 l=mid+1;
59 }
60 else r=mid-1;
61 }
62 printf("Case %d: ",s);
63 printf("%d\n",ic-id);
64 }
65 return 0;
66 }
67 void dfs(int n,int m,LL u)
68 {
69 if(n==m)
70 return ;
71 ans[N++]=u*10+4;
72 dfs(n+1,m,u*10+4);
73 ans[N++]=u*10+7;
74 dfs(n+1,m,u*10+7);
75 }
76 void dfs1(LL u,int k)
77 {
78 int i;
79 if(!my[u])
80 {
81 my[u]=1;
82 for(i=k; i<N; i++)
83 {
84 if(ans[i]<=1e12/u)
85 {
86 if(my[ans[i]*u]==0)
87 {
88 bns[M++]=ans[i]*u;
89 dfs1(ans[i]*u,i);
90 }
91 }
92 else
93 {
94 return ;
95 }
96 }
97 }
98 }
1276 - Very Lucky Numbers的更多相关文章
- HDU 5676 ztr loves lucky numbers (模拟)
ztr loves lucky numbers 题目链接: http://acm.hust.edu.cn/vjudge/contest/121332#problem/I Description ztr ...
- codeforces 630C Lucky Numbers
C. Lucky Numbers time limit per test 0.5 seconds memory limit per test 64 megabytes input standard i ...
- hdu 5676 ztr loves lucky numbers(dfs+离线)
Problem Description ztr loves lucky numbers. Everybody knows that positive integers are lucky if the ...
- codeforces 630C - Lucky Numbers 递推思路
630C - Lucky Numbers 题目大意: 给定数字位数,且这个数字只能由7和8组成,问有多少种组合的可能性 思路: 假设为1位,只有7和8:两位的时候,除了77,78,87,88之外还哇哦 ...
- hdu 5676 ztr loves lucky numbers 打表+二分
ztr loves lucky numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/ ...
- ZCMU 2177 Lucky Numbers (easy)
传送门: http://acm.zcmu.edu.cn/JudgeOnline/problem.php?id=2177 2177: Lucky Numbers (easy) 时间限制: 2 Sec ...
- hdu-5676 ztr loves lucky numbers(乱搞题)
题目链接: ztr loves lucky numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K ( ...
- C - Lucky Numbers (easy)
Problem description Petya loves lucky numbers. Everybody knows that positive integers are lucky if t ...
- Codeforces Round #160 (Div. 2)---A. Roma and Lucky Numbers
Roma and Lucky Numbers time limit per test 1 second memory limit per test 256 megabytes input standa ...
随机推荐
- Pyquery解析库的安装和使用
Pyquery同样是一个强大的网页解析工具,它提供了和jQuery类似的语法来解析HTML文档,支持CSS选择器,使用非常方便.GitHub:https://github.com/gawel/pyqu ...
- typora 图床配置方法
学习计算机的同学,在日常学习中难免会记笔记,写文档.相信大家记笔记大部分使用的都是 Markdown 吧,如果到现在还没接触,那我强烈建议你去学习一下,大概几分钟就可以搞定它. 注:下文用到的所有软件 ...
- C语言中的各种字符串输入方法
C语言从stdin读取一行字符串的几种方法 gets gets函数的头文件是<stdio.h>,原型如下: char *gets(char *s); gets从stdin中读入一行内容到s ...
- 看动画学算法之:二叉搜索树BST
目录 简介 BST的基本性质 BST的构建 BST的搜索 BST的插入 BST的删除 简介 树是类似于链表的数据结构,和链表的线性结构不同的是,树是具有层次结构的非线性的数据结构. 树是由很多个节点组 ...
- 关于java中的安全管理器
最近再查看java的源码的时候看见了这一类代码 final SecurityManager sm = System.getSecurityManager(); 想要了解这个是为了做什么,查看资料之后发 ...
- Ubuntu下STL源码文件路径+VS2010下查看STL源码
Ubuntu版本信息 然后STL源码位置就在 /usr/include/c++/7/bits /usr/include/c++/7.4.9/bits 这两个文件下都有 然后我日常写程序用的Window ...
- C逗号表达式
c语言提供一种特殊的运算符,逗号运算符,优先级别最低,它将两个及其以上的式子联接起来,从左往右逐个计算表达式,整个表达式的值为最后一个表达式的值.如:(3+5,6+8)称为逗号表达式,其求解过程先表达 ...
- C++一元多项式求导
这个题难度不大但是坑有点多,要考虑的点有几个: 1.测试用例为x 0 这个直接输出 0 0即可. 2.注意空格的输出 3.测试点3我好几次都没过,最后参考了别的答案加以修改才通过. 测试点3没过的代码 ...
- Android,iOS系统有什么区别
两者运行机制不同:IOS采用的是沙盒运行机制,安卓采用的是虚拟机运行机制.Android是一种基于Linux的自由及开源的操作系统,iOS是由苹果公司开发的移动操作系统IOS中用于UI指令权限最高,安 ...
- java web 限制同一个用户在不同处登入
用到的技术:map集合,sessionListener监听器,Fiter过滤器. 实现思路: 一.利用一个全局的map集合来保存每个用户sessionID的值的一个集合.一个用户对应一个session ...