hdu 5878 I Count Two Three

来源:互联网 发布:软件开发速成 编辑:程序博客网 时间:2024/05/22 07:45
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
1011113123123412345123456123456712345678123456789
 

Sample Output
11214125125012348123480123480012348000

123480000

打表+二分;

#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#include <stack>#include <vector>#include <queue>#include <set>#include <map>#include <string>#include <math.h>#include <stdlib.h>#include <time.h>using namespace std;#define LL long long#define N 100005#define mod 1000000007vector<LL> vec;vector<LL>::iterator it;void init(){    LL a=1,b=1,c=1,d=1;    LL sum=0;    for(int i=0;i<40;i++)    {        if(i) a*=2;        else a=1;        for(int j=0;j<40;j++)        {            if(j) b*=3;            else b=1;            for(int k=0;k<40;k++)            {                if(k) c*=5;                else c=1;                for(int l=0;l<40;l++)                {                    if(l) d*=7;                    else d=1;                    sum=a*b*c*d;                    if(sum<1||sum>1000000000)                        break;                    vec.push_back(sum);                }            }        }    }}int main(){    int T;    LL n;    init();    sort(vec.begin(),vec.end());    cin>>T;    while(T--)    {        scanf("%I64d",&n);        it=lower_bound(vec.begin(),vec.end(),n);        printf("%I64d\n",*it);    }}


0 0
原创粉丝点击