51Nod1010 只包含因子2 3 5的数 (二分
来源:互联网 发布:淘宝关键词挖掘 编辑:程序博客网 时间:2024/05/29 15:02
Description
K的因子中只包含2 3 5。满足条件的前10个数是:2,3,4,5,6,8,9,10,12,15。
所有这样的K组成了一个序列S,现在给出一个数n,求S中 >= 给定数的最小的数。
例如:n = 13,S中 >= 13的最小的数是15,所以输出15。
Input
第1行:一个数T,表示后面用作输入测试的数的数量。(1 <= T <= 10000)
第2 - T + 1行:每行1个数N(1 <= N <= 10^18)
Output
共T行,每行1个数,输出>= n的最小的只包含因子2 3 5的数。
Sample Input
5
1
8
13
35
77
Sample Output
2
8
15
36
80
题意
中文题
题解:
打表+二分 这里我是自己写的二分 还有一种是STL中的lower_bound实现查找的QAQ
AC代码
#include <cstdio>#include <cstring>#include <cmath>#include <queue>#include <stack>#include <map>#include <set>#include <iostream>#include <vector>#include <algorithm>using namespace std;#define ll long longconst int mod = 1e9+7;const ll N = 1e18+100; //当时加了个10一直wa 2*5*3>10ll arr[11000];int ans = 0;void init(){ for(ll i = 1; i < N; i*=2) { for(ll j = 1; j*i < N; j*=3) { for(ll k = 1; k*j*i < N; k*=5) { arr[ans++] = i*j*k; } } } }ll find(ll x){ ll l = 1; ll h = ans; while(l<h) { int mid = (l+h) >> 1; if(arr[mid]==x) return arr[mid]; else if(arr[mid] < x) l = mid + 1; else h = mid ; }return arr[h]; } int main(){ init(); sort(arr,arr+ans); int T; scanf("%d",&T); while(T--) { ll n; scanf("%lld",&n); printf("%lld\n",find(n)); } return 0;}
1 0
- 51nod1010 只包含因子2 3 5的数
- 51Nod1010 只包含因子2 3 5的数 (二分
- 只包含因子2 3 5的数 51nod1010
- 51nod 1010 只包含因子2 3 5的数 (打表+二分)
- 51NOD 1010 只包含因子2 3 5的数(二分 + 预处理)
- 51nod 1010 只包含因子2 3 5的数(打表+二分)
- 51nod 1010 只包含因子2 3 5的数【打表+二分】
- 51nod 1010 只包含因子2 3 5的数(预处理+二分)
- 51nod 只包含因子2 3 5的数 dfs打表+二分
- 51nod 1010 只包含因子2 3 5的数 【容器 +二分 】
- 51Nod 1010 只包含因子2 3 5的数 打表+二分
- 1010 只包含因子2 3 5的数(丑数 二分)
- 只包含因子2 3 5 的数----51Nod
- 1010 只包含因子2 3 5的数(打表+二分)
- 1010 只包含因子2 3 5的数(预处理+二分)
- 丑数,只包含因子2、3、5的数
- 51Nod-1010 只包含因子2 3 5的数【打表+排序+二分搜索】
- 1010 只包含因子2 3 5的数
- mysql行列转换
- 急急急,毕业设计,项目:基于百度lbs的车辆监控系统的设计与实现
- 从头到尾彻底解析Hash表算法
- win10环境下shadowsocks+VM12.5.2下ubuntu使用谷歌搜索
- IDEA2017.2最新版BUG
- 51Nod1010 只包含因子2 3 5的数 (二分
- 【SQL基础】case when和decode的用法与区别
- POJ2602-Superlong sums
- ORA-01017: invalid username/password; logon denied
- 关于Python的进程线程协程之大话多进程多线程
- hihoCoder 1015 : KMP算法
- POJ1062-昂贵的聘礼
- Linux中常用操作命令
- IDEA玩法- 自动补充标签(括号式)