F

题目:

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

几个月没打ACM了 ,第一眼看到这个题  咦 要数论解方程吗,然后在纸上一顿推公式,

推到一半 发现 emmmmmm   2^64>1e18    3^64>1e18  5^64>1e18
所以 在 1e18内是 2  3 8 因子的数字count<64*64*64

所以可以直接暴力 然后二分找出大于等于n的值就OK了  时间完全不是问题

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
ll num[30000];//注意数据范围
int main()
{
    int t,cnt=0;
    ll n;
    for(ll i=1;i<=1e18+1000;i*=2)
    {
        for(ll j=1;i*j<=1e18+1000;j*=3)
        {
            for(ll k=1;i*j*k<=1e18+1000;k*=5)
            {
                num[cnt++]=i*j*k;
            }
        }
    }
    sort(num,num+cnt);
    scanf("%d",&t);
    while(t--)
    {
        scanf("%lld",&n);
        int ans=lower_bound(num,num+cnt,n)-num;
        if(ans)//特别的 如果ans=0  即num[ans]为1  因子并没有2 3 5 需要特判一下
         cout<<num[ans]<<endl;
        else
            cout<<2<<endl;
    }
}
原文地址:https://www.cnblogs.com/dchnzlh/p/9780042.html