1 条题解

  • 1
    @ 2022-8-24 9:26:27
    #include <bits/stdc++.h>
    using namespace std;
    inline int read()//读入优化
    {
        int x = 0, f = 1;
        char ch = getchar();
        while (!isdigit(ch))
        {
            f = ch != '-';
            ch = getchar();
        }
        while (isdigit(ch))
        {
            x = (x << 1) + (x << 3) + (ch ^ 48);
            ch = getchar();
        }
        return f ? x : -x;
    }
    inline void write(int x)//输出优化
    {
        if (x >= 10)
            write(x / 10);
        putchar(x % 10 + 48);
    }
    const int N = 1e7 + 100;
    int T, x, ls;
    int f[N], nx[N];
    bool check(int x)//判断是否含有数字7
    {
        while (x)
        {
            if (x % 10 == 7)
                return 1;
            x /= 10;
        }
        return 0;
    }
    void init()//预处理部分
    {
        for (int i = 1; i <= N - 10; i++)
        {
            if (f[i])//如果被标记过,就跳过
                continue;
            if (check(i))//如果含有数字7,标记其倍数
            {
                for (int j = i; j <= N - 10; j += i)
                    f[j] = 1;
                continue;
            }
            nx[ls] = i;//记录i
            ls = i;//更新ls
        }
    }
    int main()
    {
        init();//先预处理
        T = read();
        while (T--)
        {
            x = read();
            if (f[x])//被标记了输出-1,否则输出nx
                puts("-1");
            else
                write(nx[x]), putchar('\n');
        }
        return 0;
    }
    
    • 1

    信息

    ID
    7079
    时间
    1000ms
    内存
    512MiB
    难度
    3
    标签
    递交数
    38
    已通过
    7
    上传者