不开数组 O(1) per ask 的下场.......
查看原帖
不开数组 O(1) per ask 的下场.......
331028
BlueGlassBlock楼主2021/11/21 14:24

rt. wssb.

二楼贴 100pts 代码.

//70 pts f**k
#include <cstdio>
#include <bitset>
using namespace std;
#define fileio(x)                 \
    freopen(x ".in", "r", stdin); \
    freopen(x ".out", "w", stdout);
template <typename T>
inline void read(T &num)
{
    num = 0;
    int f = 1;
    char ch = getchar();
    while (ch < '0' and ch > '9')
    {
        if (ch == '-')
            f = -1;
        ch = getchar();
    }
    while ('0' <= ch and ch <= '9')
    {
        num = (num << 3) + (num << 1) + (ch ^ 48);
        ch = getchar();
    }
    num *= f;
}
const int FINAL = 10000010;
bitset<FINAL> contain_7;
int tot;
int T, ask;
inline bool has_7(int x)
{
    while (x)
    {
        if (x % 10 == 7)
            return true;
        x /= 10;
    }
    return false;
}
inline int compute(int trgt)
{
    if (trgt <= tot)
    {
        if (contain_7[trgt])
            return -1;
        else
        {
            for (int i = trgt + 1; i <= tot; ++i)
            {
                if (!contain_7[i])
                    return i;
            }
        }
    }
    for (;; ++tot)
    {
        if (contain_7[tot])
            continue;
        if (has_7(tot))
        {
            for (int label = tot; label <= FINAL; label += tot)
            {
                contain_7[label] = true;
            }
            continue;
        }
        if (tot > trgt)
        {
            if (contain_7[trgt])
                return -1;
            return tot;
        }
    }
}
int main()
{
#ifndef DEBUG
    fileio("number");
#endif
    read(T);
    for (int i = 1; i <= T; ++i)
    {
        read(ask);
        printf("%d\n", compute(ask));
    }
    return 0;
}
2021/11/21 14:24
加载中...