51Nod 1010 只包含因子2 3 5的数
2016-11-29 20:53
78 查看
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
Output
Input示例
Output示例
所有这样的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示例
5 1 8 13 35 77
Output示例
2 8 15 36 80
#include<stdio.h> #include<algorithm> #define LL long long using namespace std; const LL maxn = 1e18+10000; const int N = 51000; LL a ; int cnt = 0; void Init() { for(LL i = 1; i < maxn; i*=2) for(LL j = 1; i*j < maxn; j*=3) for(LL k = 1; k*j*i < maxn; k*=5) a[cnt++] = i*j*k; } int main() { Init(); int t; sort(a, a+cnt); LL n; scanf("%d", &t); while(t--) { scanf("%lld", &n); LL l = 1, r = cnt, mid; while(l<r) { mid = (l+r)>>1; if(a[mid] >= n) { r = mid; } else l = mid+1; } printf("%lld\n", a[l]); } return 0; }
相关文章推荐
- 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的数 && poj - 1338 Ugly Numbers(打表)
- 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的数