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 ...
随机推荐
- Oracle完整的压测记录
问题描述:对oracle进行一次完整的数据压测,从制造数据到压测的过程,路上踩了一些坑,现在分享出来 1.下载swingbenh软件,一个比较好用的oracle压测软件 2.利用oewizard工具( ...
- C语言中的字节对齐
下面这个篇博客讲解很好 http://blog.csdn.net/meegomeego/article/details/9393783 总的来看分三类: 1. 不加 #pragma pack(n)伪指 ...
- Hive(二)【数据类型、类型转换】
目录 一.基本数据类型 案例实操 二.集合数据类型 案例实操 Map类型 三.类型转换 1.隐式类型转换 2.显示(强制)类型转换 一.基本数据类型 HIVE MySQL JAVA 长度 例子 TIN ...
- 大数据学习day17------第三阶段-----scala05------1.Akka RPC通信案例改造和部署在多台机器上 2. 柯里化方法 3. 隐式转换 4 scala的泛型
1.Akka RPC通信案例改造和部署在多台机器上 1.1 Akka RPC通信案例的改造(主要是把一些参数不写是) Master package com._51doit.akka.rpc impo ...
- navicate连接Mysql5.7时,显示Access denied for user 'root'@'localhost' (using password: YES) 错误
最近新装了Mysql5.7,按如下设置好了允许远程连接 (1)找到mysql配置文件并修改 sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf 将bind-ad ...
- 剑指 Offer 10- I. 斐波那契数列
写一个函数,输入 n ,求斐波那契(Fibonacci)数列的第 n 项(即 F(N)).斐波那契数列的定义如下: F(0) = 0, F(1) = 1F(N) = F(N - 1) + F(N ...
- SqlSession与SqlSessionFactory到底是什么关系?
1. SqlSession和SqlSessionFactory的接口定义 SqlSession: public interface SqlSession extends Closeable { ...
- 删除数据库时报错 ERROR 1010 (HY000): Error dropping database (can't rmdir './cart', errno: 39)
这是因为在数据目录下有表相关的数据(不是表),此时应该进入存放表的目录下删除与表相关的数据,一般数据存放目录默认为/var/lib/mysql,cd到目录下 执行命令:cd /var/lib/mysq ...
- 【Services】【Web】【tomcat】配置tomcat支持https传输
1. 基础: 1.1. 描述:内网的tomcat接到外网nginx转发过来的请求之后需要和外网的客户端进行通讯,为了保证通讯内容的安装,使用tomcat使用https协议. 1.2. 链接:http: ...
- .net core容器添加时区和libgdi+和下载加速
国内.net core镜像下载加速 比如对于mcr.microsoft.com/dotnet/core/aspnet:3.1,下载是走的azure全球cdn,国内访问很慢. 国内访问可以把mcr.mi ...