Problem A. I Count Two Three(The 2016 ACM-ICPC Asia Qingdao Regional Contest, Online)

Problem A. I Count Two Three(点击转到
Time limit: 1s
Color of balloons: 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 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
standard input
10
1
11
13
123
1234
12345
123456
1234567
12345678
123456789

standard output
1
12
14
125
1250
12348
123480
1234800
12348000
123480000

1.题目含义:

    定义”I Count Two Three Number”为:pow(2,a)*pow(3,b)*pow(5,c)*pow(7,d).。求满足大于n的最小的”I Count Two Three Number”。

2.倘若每次读入n进行重复的运算,那是非常不合理的,可以预处理一下数据。

3  lower_bound()和upper_bound()的用法

    lower_bound(num,num+n,x) 返回num数组中大于等于x中,且是最小的数的指针

    upper_bound(num,num+n,x) 返回num数组中大于x中,且是最小的数的指针

   点击查看详情

#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int mod = 1e9;
int bas[4] = {2,3,5,7};
int num[23333];
int r;
void begin(int pos,LL v)
{
    if(pos == 4)
    {
        num[r++] = v;
        return;
    }
    while(v <= mod)
    {
        begin(pos+1,v);
        v=v*bas[pos];
    }
}
int main()
{
    r = 0;
    begin(0,1);
    sort(num,num+r);
    int t,n;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        printf("%d\n",*lower_bound(num,num+r,n));
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/SSYITwin/article/details/81669329