51nod 1010 只包含因子2 3 5的数 打表

时间:2023-03-09 14:41:19
51nod 1010 只包含因子2 3 5的数 打表

只包含因子2 3 5的数

题目连接:

http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1010

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

Hint

题意

题解:

数很少,预先打表,然后打完表直接二分去查找就好了

代码

#include<bits/stdc++.h>
using namespace std; map<long long,int>H;
vector<long long>T;
long long d[3]={2,3,5};
void init()
{
for(int i=0;i<3;i++)T.push_back(d[i]),H[d[i]]=1;
for(int i=0;i<T.size();i++)
{
if(T[i]>1e18)continue;
for(int j=0;j<3;j++)
{
long long tmp = T[i]*d[j];
if(H[tmp])continue;
H[tmp]=1;
T.push_back(tmp);
}
}
sort(T.begin(),T.end());
}
int main()
{
init();
int t;scanf("%d",&t);
while(t--)
{
long long n;
cin>>n;
long long ans = *lower_bound(T.begin(),T.end(),n);
printf("%lld\n",ans);
}
}