zoukankan      html  css  js  c++  java
  • hdu 5878

    I Count Two Three

    Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 2719    Accepted Submission(s): 1177


    Problem Description
    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 i-th attacks failed if and only if i can be rewritten as the form of 2a3b5c7d which a,b,c,d are non-negative integers.

    At recent dinner parties, we call the integers with the form 2a3b5c7d "I Count Two Three Numbers".
    A related board game with a given positive integer n from one agent, asks all participants the smallest "I Count Two Three Number" no smaller than n.
     
    Input
    The first line of input contains an integer t (1t500000), the number of test cases. t test cases follow. Each test case provides one integer n (1n109).
     
    Output
    For each test case, output one line with only one integer corresponding to the shortest "I Count Two Three Number" no smaller than n.
     
    Sample Input
    10 1 11 13 123 1234 12345 123456 1234567 12345678 123456789
     
    Sample Output
    1 12 14 125 1250 12348 123480 1234800 12348000 123480000
     
    Source
     
     
     
     1 #include <iostream>
     2 #include <cstdio>
     3 #include <algorithm>
     4 #include <cstdlib>
     5 #include <cstring>
     6 #include <string>
     7 #include <deque>
     8 #include <vector>
     9 #include <set>
    10 using namespace std;
    11 #define ll long long 
    12 #define P pair<int,int>
    13 const int N= 5e3+1000;
    14 const ll  M = 1000000000;
    15 ll n,a[N];
    16 int cnt =0;
    17 int t;
    18 ll pow(ll a,ll b){
    19     ll ans=1;
    20     while(b){
    21         if(b&1) ans=ans*a;
    22         b>>=1;
    23         a*=a;
    24     }
    25     return ans;
    26 }
    27 void init()
    28 {
    29     ll i,j,k,l;
    30     for(i=0;i<=32;i++){
    31         if(pow(2,i)>M) break;
    32         for(j=0;j<=32;j++){
    33             if(pow(2,i)*pow(3,j)>M) break;
    34             for(k=0;k<=32;k++) {//k++后,l 再次从0开始。 
    35                 if(pow(2,i)*pow(3,j)*pow(5,k)>M) break;
    36                 for(l=0;l<=32;l++){
    37                     if(pow(2,i)*pow(3,j)*pow(5,k)*pow(7,l)>M) break;//在这里跳出才可以继续循环 
    38                     a[cnt++] = pow(2,i)*pow(3,j)*pow(5,k)*pow(7,l);
    39                 }
    40             }
    41         }
    42     }
    43     sort(a,a+cnt);
    44 }
    45 int main()
    46 {
    47     
    48     init();
    49     scanf("%d",&t);
    50     while(t--){
    51         scanf("%lld",&n);
    52         printf("%lld
    ",a[lower_bound(a,a+cnt,n)-a]);
    53     }
    54     return 0;
    55 }
  • 相关阅读:
    企业级开发的权限管理
    asp.net mvc 中的ajax
    拖拽(非原创)
    数据库中主键和外键的设计原则
    第六篇续:动态创建 ListView 模板
    动态创建 ASP.NET Web 服务器控件模板(出自MSDN)
    ASP.NET跨页面传值的几种方法
    奇文共赏 史记货殖列传王石传
    需求该如何分析?
    PopupControlExtender 控件的使用(转)
  • 原文地址:https://www.cnblogs.com/tingtin/p/9488136.html
Copyright © 2011-2022 走看看