zoukankan      html  css  js  c++  java
  • 51Nod 1010 只包含因子2 3 5的数(打表+二分)

    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的数。
    Input示例
    5
    1
    8
    13
    35
    77
    Output示例
    2
    8
    15
    36
    80
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <cstdio>
    #include <vector>
    #include <queue>
    #include <stack>
    #include <cstdlib>
    #include <iomanip>
    #include <cmath>
    #include <cassert>
    #include <ctime>
    #include <map>
    #include <set>
    using namespace std;
    #pragma comment(linker, "/stck:1024000000,1024000000")
    #define lowbit(x) (x&(-x))
    #define max(x,y) (x>=y?x:y)
    #define min(x,y) (x<=y?x:y)
    #define MAX 100000000000000000
    #define MOD 1000000007
    #define pi acos(-1.0)
    #define ei exp(1)
    #define PI 3.1415926535897932384626433832
    #define ios() ios::sync_with_stdio(true)
    #define INF 0x3f3f3f3f
    #define mem(a) ((a,0,sizeof(a)))
    typedef long long ll;
    #define maxn 1e18
    ll dp[1000006],n,t,top=0;
    int main()
    {
        for(ll i=1;i<=maxn;i*=2)
        {
            for(ll j=1;j*i<=maxn;j*=3)
            {
                for(ll k=1;k*i*j<=maxn;k*=5)
                {
                    dp[top++]=i*j*k;
                }
            }
        }
        sort(dp,dp+top);
        scanf("%lld",&t);
        while(t--)
        {
            scanf("%lld",&n);
            printf("%lld
    ", *lower_bound(dp+1,dp+top,n));
        }
        return 0;
    }
  • 相关阅读:
    jQuery 折叠,自动完成,小提示,树,验证插件(bassistance.de)
    多样化的连结提示效果(Tips)
    Ext开源 Extjs2.0 人力资源管理(ASP.NET)
    JavaScript面向对象编程
    访问Ext.data.store的数据
    Ext核心代码分析之Function.createDelegate
    支持firefox的省略符
    Ext 2.0下Jquery的整合使用示例
    多样化的垂直菜单(OUTLOOK菜单)
    使用 jQuery 简化 Ajax 开发
  • 原文地址:https://www.cnblogs.com/shinianhuanniyijuhaojiubujian/p/8949435.html
Copyright © 2011-2022 走看看