HUST 1600 Lucky Numbers
来源:互联网 发布:windows 垃圾清理 编辑:程序博客网 时间:2024/05/09 03:31
Description
Isun loves digit 4 and 8 very much. He thinks a number is lucky only if the number satisfy the following conditions:
1. The number only consists of digit 4 and 8.
2. The number multiples 48.
One day, the math teacher gives Isun a problem:
Given L and R(1 <= L <= R <= 10^15), how many lucky numbers are there between L and R. (i.e. how many x satisfy L <= x <= R, x is a lucky number).
1. The number only consists of digit 4 and 8.
2. The number multiples 48.
One day, the math teacher gives Isun a problem:
Given L and R(1 <= L <= R <= 10^15), how many lucky numbers are there between L and R. (i.e. how many x satisfy L <= x <= R, x is a lucky number).
Input
Multiple test cases. For each test case, there is only one line consist two numbers L and R.
Output
For each test case, print the number of lucky numbers in one line.
Do use the % lld specifier or cin/ cout stream to read or write 64-bit integers in С++.
Do use the % lld specifier or cin/ cout stream to read or write 64-bit integers in С++.
Sample Input
1 481 484848
Sample Output
17
直接预处理出全部的lucky number,然后每次询问可以直接二分找到区间,相减就是答案。
#include<cstdio>#include<string>#include<cstring>#include<vector>#include<iostream>#include<queue>#include<map>#include<bitset>#include<algorithm>using namespace std;typedef long long LL;const int INF = 0x7FFFFFFF;const int mod = 1e9 + 7;const int maxn = 3e5 + 10;LL l, r;LL a[maxn], tot;void dfs(int x, LL y){if (x == 15) return;if (y % 48 == 0) a[tot++] = y;dfs(x + 1, y * 10 + 4);dfs(x + 1, y * 10 + 8);}int main(){tot = 0; dfs(0, 0);sort(a, a + tot);while (scanf("%lld%lld", &l, &r) != EOF){int x = lower_bound(a, a + tot, l) - a;int y = upper_bound(a, a + tot, r) - a;printf("%d\n", y - x);}return 0;}
0 0
- HUST 1600 Lucky Numbers
- HUST 1600 Lucky Numbers
- HUST-1600 - Lucky Numbers 深搜
- Lucky Numbers
- Lucky Numbers
- Lucky Numbers
- hust-Integer Numbers
- hust 1003 - Sibonacci Numbers
- [bnu] 4104 Lucky numbers
- hust1600 Lucky Numbers 小水题
- F: Lucky Numbers
- UVa11970 - Lucky Numbers
- C - Lucky Numbers
- Lucky Numbers(acm)
- C. Lucky Numbers
- hdu_5676_ztr loves lucky numbers
- hdoj5676ztr loves lucky numbers
- Lucky Numbers (easy)
- StringBuffer和StringBuilder存在的作用是什么
- 当前主流的导航控制器手势滑动效果
- Java-猜拳游戏
- Sudoku Killer
- Python 字符串方法详解
- HUST 1600 Lucky Numbers
- launchMode affinity allowTaskReparent
- 编译环境
- error C2099: 初始值设定项不是常量
- hust 1602
- 简明 Python 编程规范v2
- GitHub新手教程
- Spring MVC之@PathVariable @RequestHeader, @CookieValue@RequestParam @RequestBody @RequestHeader 等详解
- eclipse调试