hdu 5878 二分+打表

来源:互联网 发布:网络教育档案存放 编辑:程序博客网 时间:2024/05/16 08:17



链接:戳这里


I Count Two Three

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

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 (1≤t≤500000), the number of test cases. t test cases follow. Each test case provides one integer n (1≤n≤109).
 
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
 

题意:

给出一个整数nn, 找出一个大于等于nn的最小整数mm, 使得mm可以表示为2^a3^b5^c7^d2a3b5c7d.

思路:

预处理出所有形为2^a3^b5^c7^d2a3b5c7d即可, 大概只有几k个.然后二分就可以了


代码:

#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<string>#include<vector>#include <ctime>#include<queue>#include<set>#include<map>#include<list>#include<stack>#include<iomanip>#include<cmath>#include<bitset>#define mst(ss,b) memset((ss),(b),sizeof(ss))///#pragma comment(linker, "/STACK:102400000,102400000")typedef long long ll;typedef long double ld;#define INF (1ll<<60)-1#define Max 1e9using namespace std;int T;ll anw[1000100];ll Pow(int x,int num){    ll ans=1LL;    for(int i=1;i<=num;i++) ans=ans*1LL*x;    return ans;}ll n;int main(){    int cnt=0;    for(int i=0;i<=31;i++){        for(int j=0;j<=19;j++){            for(int k=0;k<=12;k++){                for(int l=0;l<=11;l++){                    ll tmp=Pow(2,i)*Pow(3,j);                    if(tmp>1e9) break;                    tmp*=Pow(5,k);                    if(tmp>1e9) break;                    tmp*=Pow(7,l);                    if(tmp>1e9) break;                    anw[++cnt]=tmp;                }            }        }    }    sort(anw+1,anw+cnt+1);    scanf("%d",&T);    while(T--){        scanf("%I64d",&n);        int x=lower_bound(anw+1,anw+cnt+1,n)-anw;        printf("%I64d\n",anw[x]);    }    return 0;}



0 0
原创粉丝点击