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;
    }
  • 相关阅读:
    点击劫持漏洞之理解 python打造一个挖掘点击劫持漏洞的脚本
    URL重定向漏洞,python打造URL重定向漏洞检测脚本
    动态链接库(DLL)
    vs不支持通过afxgetmainwnd()获取窗口句柄(转)
    HALCON学习-下载、安装
    HALCON学习-资料
    MFC,ADO方式实现数据库操作
    VS2010 EXCEL2010 表格操作的编程实现
    Git Compare with base,比较大文件时,长时间等待,无法加载
    VS2010编译VS2008工程时,LINK : fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt
  • 原文地址:https://www.cnblogs.com/yzm10/p/9477438.html
Copyright © 2011-2022 走看看