zoukankan      html  css  js  c++  java
  • HDU

    I Count Two Three 

    •  31.1%
    •  1000ms
    •  32768K
     

    I will show you the most popular board game in the Shanghai Ingress Resistance Team.

    It all started several months ago.

    We found out the home address of the enlightened agent Icount2three and decided to draw him out.

    Millions of missiles were detonated, but some of them failed.

    After the event, we analysed the laws of failed attacks.

    It's interesting that the ii-th attacks failed if and only if ii can be rewritten as the form of 2^a3^b5^c7^d2a3b5c7d which a, b, c, da, b, c, d are non-negative integers.

    At recent dinner parties, we call the integers with the form 2^a3^b5^c7^d2a3b5c7d "I Count Two Three Numbers".

    A related board game with a given positive integer nn from one agent, asks all participants the smallest "I Count Two Three Number" no smaller than nn.

    Input Format

    The first line of input contains an integer t (1le t le 500000)t(1t500000), the number of test cases. tt test cases follow. Each test case provides one integer n (1le nle 10^9)n(1n109).

    Output Format

    For each test case, output one line with only one integer corresponding to the shortest "I Count Two Three Number" no smaller than nn.

    样例输入

    10
    1
    11
    13
    123
    1234
    12345
    123456
    1234567
    12345678
    123456789

    样例输出

    1
    12
    14
    125
    1250
    12348
    123480
    1234800
    12348000
    123480000

    题目来源

    ACM-ICPC 2016 Qingdao Preliminary Contest

     

     

    这道题类似于之前的51Nod - 1284找2 3 5 7的倍数,求出2 3 5 7最小公倍数210找循环节。

    本题是2^a*3^b*5^c*7^d,无法从gcd循环节入手,于是就把10^9之内满足条件的值打出表来,发现只有5194个。

    由于t很大,将表排个序,二分查找即可。

     

    #include<stdio.h>
    #include<algorithm>
    #define MAX 5200
    #define INF 0x3f3f3f3f
    using namespace std;
    typedef long long ll;
    ll a[MAX];
    ll mul(ll init,int x,int c)
    {
        ll ans=init;
        for(int i=1;i<=c;i++){
            ans*=x;
            if(ans>1000000000) return 0;
        }
        return ans;
    }
    int main()
    {
        int t,i,j,k,l;
        int tt=0;
        for(i=0;i<=31;i++){
            ll ii=mul(1,2,i);
            if(ii==0) continue;
            for(j=0;j<=31;j++){
                ll jj=mul(ii,3,j);
                if(jj==0) continue;
                for(k=0;k<=31;k++){
                    ll kk=mul(jj,5,k);
                    if(kk==0) continue;
                    for(l=0;l<=31;l++){
                        ll lll=mul(kk,7,l);
                        if(lll==0) continue;
                        a[++tt]=lll;
                    }
                }
            }
        }
        sort(a+1,a+tt+1);
        ll n;
        scanf("%d",&t);
        while(t--){
            scanf("%lld",&n);
            ll ans=INF;
            int l=1,r=tt,m;
            while(l<=r){
                m=(l+r)/2;
                if(a[m]==n){
                    ans=n;
                    break;
                }
                if(a[m]<n){
                    l=m+1;
                }
                else{
                    if(a[m]<ans) ans=a[m];
                    r=m-1;
                }
            }
            printf("%lld
    ",ans);
        }
        return 0;
    }
  • 相关阅读:
    Nagios显示器mysql定从库: libmysqlclient.so.18: cannot open shared object file: No such
    UVA 11402
    Oracle 11g 的PL/SQL函数结果缓存
    最大公约数(Greatest Common Divisor)
    计时器 Timer
    ArcGIS Engine 捕捉
    AE+C# 图层中增加相应属性标注
    C# ComboBox自动完成功能的示例
    Visual Assist的破解与安装
    GitHub的代码托管和使用方法
  • 原文地址:https://www.cnblogs.com/yzm10/p/9477438.html
Copyright © 2011-2022 走看看