zoukankan      html  css  js  c++  java
  • 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;
        }
    }
    
  • 相关阅读:
    centos7安装ELS7.2.1
    简单搭建es环境并配置keyword检索
    拦截器执行顺序及查看方法
    JPA同时支持精准搜索和模糊搜索
    Vue开发之devtools
    Linux配置本地yum源
    Nginx编译安装
    VS2017 DUMP文件调试
    磁共振序列相关知识点记录
    C#高级编程笔记(一)
  • 原文地址:https://www.cnblogs.com/dchnzlh/p/9780042.html
Copyright © 2011-2022 走看看