1 条题解

  • 0
    @ 2023-4-15 17:03:28
    #include <bits/stdc++.h>
    using namespace std;
    int n;
    const int MAXN = 512345;
    bool vis[MAXN];
    int ptot, phi[MAXN], pri[MAXN];
    void init()
    {
        phi[1] = 1;
        for (int i = 2; i < MAXN; ++i)
        {
            if (!vis[i])
                phi[i] = i - 1, pri[ptot++] = i;
            for (int j = 0; j < ptot; ++j)
            {
                if (1ll * i * pri[j] >= MAXN)
                    break;
                vis[i * pri[j]] = 1;
                if (i % pri[j])
                    phi[i * pri[j]] = phi[i] * (pri[j] - 1);
                else
                {
                    phi[i * pri[j]] = phi[i] * pri[j];
                    break;
                }
            }
        }
    }
    int main()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
        init();
        cin >> n;
        if (n == 1)
        {
            cout << "1\n1\n";
            return 0;
        }
        if (n == 2)
        {
            cout << "1\n1\n1\n";
            return 0;
        }
        n++;
        cout << 2 << "\n";
        for (int i = 2; i <= n; i++)
            if (vis[i])
                cout << 1 << " ";
            else
                cout << 2 << " ";
        return 0;
    }
    
    • 1

    信息

    ID
    1262
    时间
    1000ms
    内存
    256MiB
    难度
    8
    标签
    递交数
    73
    已通过
    10
    上传者