E - Everybody loves acai Gym - 102448E(打表)

Gabriel is a student from UFPE that loves acai (he really loves it). As he is really passionate about it, he became very picky about how much acai a perfect bowl should have.

A bowl is said to be perfect if the volume of acai in it is a perfect number.

A perfect number is a positive integer that is equal to the sum of its positive divisors, excluding the number itself.

Gabriel decided to go to different restaurants and ask how much acai they have. Your task is to help him get the biggest perfect bowl on each of them or declare it is impossible.

Input
The first line of input contains an integer n (1≤n≤2⋅106), the number of restaurants Gabriel will visit. Each of the next n lines contains an integer ki (1≤ki≤2⋅106), the amount of acai the i-th restaurant has.

Output
Output should consist of n lines. The i-th of them must contain an integer ai, the biggest acai Gabriel can have at the i-th restaurant, or −1 if it’s not possible to have a perfect acai.

Example
Input
2
8
5
Output
6
-1
Note
In the first example, the answer is 6, since it’s the biggest perfect number lower than or equal to 8.
List of divisors of 8, excluding itself => [1,2]
List of divisors of 7, excluding itself => [1]
List of divisors of 6, excluding itself => [1,2,3]
In the second example, the answer is −1, since we don’t have any perfect number lower than or equal to 5.
List of divisors of 5, excluding itself => [1]
List of divisors of 4, excluding itself => [1,2]
List of divisors of 3, excluding itself => [1]
List of divisors of 2, excluding itself => [1]
List of divisors of 1, excluding itself => []

題意:
求一個不大於x的最大數,其約數(不包括本身)和爲本身。

思路:
打表,打完發現就只有幾個數。。。

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

int a[2000] = {6,28,496,8128};

int main() {
    int n;scanf("%d",&n);
    for(int i = 1;i <= n;i++) {
        int x;scanf("%d",&x);
        if(x <= 5) {
            printf("-1\n");
        }
        else {
            for(int j = 3;j >= 0;j--) {
                if(a[j] <= x) {
                    printf("%d\n",a[j]);
                    break;
                }
            }
        }
    }
    return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章