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 ...
随机推荐
- ProxyApi-大数据采集用的IP代理池
用于大数据采集用的代理池 在数据采集的过程中,最需要的就是一直变化的代理ip. 自建adsl为问题是只有一个区域的IP. 买的代理存在的问题是不稳定,影响采集效率. 云vps不允许安装花生壳等,即使有 ...
- 添加页面、页面交互、动态添加页面tab
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ViewDictTosPr ...
- 疯了吧!这帮人居然用 Go 写“前端”?(一)
作者 | 郑嘉涛(羣青) 来源 | 尔达 Erda 公众号 无一例外,谈到前后端分离"必定"是 RESTful API,算是定式了.但我们知道 REST 在资源划分上的设计总是 ...
- 【讨论】APP的免填邀请码解决方案
00x0 具体需求 app中已注册的用户分享一个含有邀请码的二维码,分享到朋友圈新用户在朋友圈打开这个这个链接下载app.新用户安装后打开app后就自动绑定邀请码要求用户不填写任何东西 朋友老板出差给 ...
- 零基础学习java------33---------http协议,tomcat(其如何在eclipse上发布),注册案例
一. HTTP协议 https://www.cnblogs.com/vamei/archive/2013/05/11/3069788.html 二. tomcat---------->web服务 ...
- 轻松理解webpack热更新原理
一.前言 - webpack热更新 Hot Module Replacement,简称HMR,无需完全刷新整个页面的同时,更新模块.HMR的好处,在日常开发工作中体会颇深:节省宝贵的开发时间.提升开发 ...
- Bootstrap-table动态表格
在开发中遇到一个需要动态生成table的需求,包括表头和数据.在调试的过程中遇到很多问题,包括数据分页,解决之后记录一下. 如下代码的数据加载流程: ①表头是动态的,在初始化table之前需要调一次后 ...
- 【编程思想】【设计模式】【其他模式】blackboard
Python版 https://github.com/faif/python-patterns/blob/master/other/blackboard.py #!/usr/bin/env pytho ...
- Linux下查看JDK安装路径
在安装好Git.JDK和jenkins之后,就需要在jenkins中进行对应的设置,比如在全局工具配置模块,需要写入JDK的安装路径. 这篇博客,介绍几种常见的在Linux中查看JDK路径的方法... ...
- linux系统下命令的学习
本博客是本人工作时做的笔记 ps aux |grep ^profile |grep A190200024 ^ 表示行首匹配 linux查看文件大小: 具体可查看:https://www.cnblogs ...