51nod 1010 只包含因子2 3 5的数
来源:互联网 发布:淘宝分销订单怎么处理 编辑:程序博客网 时间:2024/06/05 16:09
1010 只包含因子2 3 5的数
基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题
收藏
关注
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的数。
Input示例
518133577
Output示例
28153680
ForwardIter lower_bound(ForwardIter first, ForwardIter last,const _Tp& val)算法返回一个非递减序列[first, last)中的第一个大于等于值val的位置。
ForwardIter upper_bound(ForwardIter first, ForwardIter last, const _Tp& val)算法返回一个非递减序列[first, last)中第一个大于val的位置。
用法如下:
#include <iostream> #include <algorithm>//必须包含的头文件 using namespace std; int main(){ int point[10] = {1,3,7,7,9}; int tmp = upper_bound(point, point + 5, 7) - point;//按从小到大,7最多能插入数组point的哪个位置 printf("%d\n",tmp); tmp = lower_bound(point, point + 5, 7) - point;////按从小到大,7最少能插入数组point的哪个位置 printf("%d\n",tmp); return 0; }
#include<bits/stdc++.h>using namespace std;typedef long long LL;const LL INF = 1e18+1000;const int MAXN = 1e6;LL a[MAXN];int cnt;void Init(){ cnt = 0; for(LL i=1; i<INF; i*=2) for(LL j=1; j*i<INF; j*=3) for(LL k=1; i*j*k<INF; k*=5) a[cnt++] = i*j*k;}int main(){ Init(); sort(a,a+cnt); int t; cin>>t; while(t--) { LL n; scanf("%lld",&n); printf("%lld\n",a[lower_bound(a+1,a+cnt+1,n)-a]); } return 0;}
阅读全文
0 0
- 只包含因子2 3 5 的数----51Nod
- 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 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 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 1010 只包含因子2 3 5的数
- 51nod 1010 只包含因子2 3 5的数(预处理+二分)
- i++和++i的那些陷阱坑
- 51nod 1307 绳子与重物 二分+dfs
- C++调python
- 哈夫曼树(数据结构)
- C++ 支持中文标识符?
- 51nod 1010 只包含因子2 3 5的数
- 一个经典例子让你彻彻底底理解java回调机制
- Kafka 的优化及在商业平台中的应用
- storm初识
- pycharm奇异的事
- 11-15
- 在增删改查中曾经用到过的页面跳转
- Ubuntu 安装 Tomcat7
- Github 理解