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 ...
随机推荐
- 日常Java测试 2021/11/14
课堂测试三 package word_show; import java.io.*;import java.util.*;import java.util.Map.Entry; public clas ...
- Spark(四)【RDD编程算子】
目录 测试准备 一.Value类型转换算子 map(func) mapPartitions(func) mapPartitions和map的区别 mapPartitionsWithIndex(func ...
- 修改linux文件权限命令:chmod 转载至 Avril 的随笔
Linux系统中的每个文件和目录都有访问许可权限,用它来确定谁可以通过何种方式对文件和目录进行访问和操作. 文件或目录的访问权限分为只读,只写和可执行三种.以文件为例,只读权限表示只允许读其内容,而禁 ...
- MyBatis 如何实现流式查询
基本概念 流式查询指的是查询成功后不是返回一个集合而是返回一个迭代器,应用每次从迭代器取一条查询结果.流式查询的好处是能够降低内存使用. 如果没有流式查询,我们想要从数据库取 1000 万条记录而又没 ...
- EM配置问题
配置EM,首先要保证dbconsole在运行. C:\Users\dingqi>emctl start dbconsoleEnvironment variable ORACLE_UNQNAME ...
- SVN终端演练-版本回退
1. 版本回退概念以及原因? 概念: 是指将代码(本地代码或者服务器代码), 回退到之前记录的某一特定版本 原因: 如果代码做错了, 想返回之前某个状态重做;2. 修改了,但未提交的情况下 ...
- Dubbo管控平台
2019年初,官方发布了Dubbo管理控制台0.1版本.结构上采取了前后端分离的方式,前端使用Vue和Vuetify分别作为Javascript框架和UI框架,后端采用Spring Boot框架 一. ...
- 【Linux】【Basis】磁盘分区
1. Linux磁盘及文件系统管理 1.1. 基本概念: 1.1.1. 磁盘接口类型: IDE(ata):并口,133MB/s,设备/dev/hd[a-z] SCSI:并口,Ultrascsi320, ...
- VectorCAST - 通过确保测试的完整性控制产品质量
软件测试面临的问题有一句格言是这样说的,"如果没有事先做好准备,就意味着做好了 失败的准备."如果把这个隐喻应用在软件测试方面,就可以这样说"没有测试到,就意味着测试失败 ...
- JavaEE期末复习
期末复习 基础 jsp技术中嵌入java代码,使用的符号 <%%> 掌握jsp技术中引用其他标签库指令标签的书写 掌握jsp技术中request对象setAttribute( ).setC ...