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


Problem DesI will show you the most popular board game in the Shanghai Ingress Resistance TeIt all started several months agoWe 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 failedAfter the event, we analysed the laws of failed attacks.
It's interesting that the d are non-negative integers.

At recent dinner parties, we call the integers with the formA related board game with a given positive integer n .
 

 

Input
The first line of input contains an integer ) .
 

 

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
 
题意:对于每一个输入的N,找一个不小于N的最小的满足条件的值(使得这个值的因子是2,3,5,7)
思路:暴力,之后二分搜索来查找。
AC代码:
#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = 1000000000 + 5;
const int N_MAX =5200;
typedef long long LL;
//LL table[10000];
LL a[N_MAX] = {0,1,2,3,4,5,6,7,8,9,10};
LL p[4] = { 2,3,5,7 };
int main() {
    int T,n;
    for (int i = 10;i < N_MAX;i++) {
        a[i] = INT_MAX;
        int k = i - 1;
        for (int j = 0;j < 4;j++) {
            while (a[k-1] * p[j]>a[i - 1])
                k--;
            a[i] = min(a[i],a[k]*p[j]);
        }
    }
    /*int cnt = 0;
    for (LL a =1;a <maxn;a*=2) {
        for (LL b=1;a*b <maxn;b*=3) {
            for (LL c = 1;a*b*c < maxn;c *= 5) {
                for (LL d = 1;a*b*c*d < maxn;d *= 7) {
                    table[cnt++] = a*b*c*d;
                }
            }
        }
    }
    sort(table, table + cnt);*/
    scanf("%d",&T);
    while (T--) {
        scanf("%d",&n);
        int id=*lower_bound(a+1, a +N_MAX,n);
        printf("%d\n", id);
    }
    
    return 0;
}

 

相关文章:

  • 2022-12-23
  • 2022-02-01
  • 2022-12-23
  • 2021-09-03
  • 2021-11-03
  • 2021-11-05
  • 2021-09-07
  • 2022-12-23
猜你喜欢
  • 2021-08-15
  • 2021-09-10
  • 2022-12-23
  • 2021-12-31
  • 2022-12-23
  • 2021-04-08
  • 2022-12-23
相关资源
相似解决方案