题干:
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
解题报告:
注意这题、、、打表的时候需要时刻加条件判断(其实只在最内层加也可以),不然就炸了呀兄dei,你在表中存了一个越界的数字,了得吗。。。肯定wa啊。
AC代码:
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll biao[1000005],tmp;
int cnt=-1;
void db() {
for(ll i = 1; i<=(ll)1e18; i*=2) {
for(ll j = 1; j*i<=(ll)1e18; j*=3) {
for(ll k = 1; k*i*j<=(ll)1e18; k*=5) {
biao[++cnt] = i*j*k;
}
}
}
// printf("%d\n",cnt);
}
int main()
{
db();
sort(biao+1,biao+cnt+1);
int t;
cin>>t;
while(t--) {
scanf("%lld",&tmp);
printf("%lld\n",*lower_bound(biao+1,biao+cnt+1,tmp));
}
return 0 ;
}