Ehab and a Special Coloring Problem

You're given an integer nn. For every integer ii from 22 to nn, assign a positive integer aiai such that the following conditions hold:

  • For any pair of integers (i,j)(i,j), if ii and jj are coprime, aiajai≠aj.
  • The maximal value of all aiai should be minimized (that is, as small as possible).

A pair of integers is called coprime if their greatest common divisor is 11.

Input

The only line contains the integer nn (2n1052≤n≤105).

Output

Print n1n−1 integers, a2a2, a3a3, …, anan (1ain1≤ai≤n).

If there are multiple solutions, print any of them.

Examples
input
Copy
4
output
Copy
1 2 1 
input
Copy
3
output
Copy
2 1
Note

In the first example, notice that 33 and 44 are coprime, so a3a4a3≠a4. Also, notice that a=[1,2,3]a=[1,2,3] satisfies the first condition, but it's not a correct answer because its maximal value is 33.


素数筛选:

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <numeric>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define mod 998244353
using namespace std;
int dir[4][2] = { {0,1},{0,-1},{-1,0},{1,0} };
const int maxn = 1e5 + 5;

int main() 
{
    int n; 
    cin >> n;
    int cnt=0;
    vector<int> a(maxn);
    vector<bool> b(maxn);
    for (int i = 2; i <= n; i++) 
    {
        if (!b[i]) 
        {
            a[i] = ++cnt;
            for (int j = i + i; j <= n; j += i)
                b[j] = 1, a[j] = a[i];
        }
    }

    for (int i = 2; i <= n; i++)
        cout << a[i] << " ";
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/dealer/p/12334517.html