p355.cpp
======================
#include <bits/stdc++.h>
#define endl '\n'

// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")

#define SZ(x) ((int)x.size())
#define ALL(V) V.begin(), V.end()
#define L_B lower_bound
#define U_B upper_bound
#define pb push_back

using namespace std;
template<class T, class T2>
inline int chkmax(T& x, const T2& y) {
    return x < y ? x = y, 1 : 0;
}
template<class T, class T2>
inline int chkmin(T& x, const T2& y) {
    return x > y ? x = y, 1 : 0;
}
const int MAXN = (1 << 20);

int n;

void read() { cin >> n; }

int answer[MAXN];
vector<int> adj[MAXN];
bool used[MAXN];

void solve() {
    for(int i = 1; i <= n; i++) {
        answer[i] = 1;
    }
    for(int i = 1; i <= n; i++) {
        for(int j = i * 2; j <= n; j += i) {
            adj[j].pb(i);
        }
    }

    for(int i = 1; i <= n; i++) {
        for(int v: adj[i]) {
            used[answer[v]] = 1;
        }
        while(used[answer[i]]) {
            answer[i]++;
        }
        for(int v: adj[i]) {
            used[answer[v]] = 0;
        }
    }

    int mx_col = 1;
    for(int i = 1; i <= n; i++) {
        chkmax(mx_col, answer[i]);
    }

    cout << mx_col << endl;
    for(int i = 1; i <= n; i++) {
        cout << answer[i] << " ";
    }
    cout << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    read();
    solve();
    return 0;
}

=================
statement.txt
======================
355. Numbers Painting
Time limit per test: 0.25 second(s)
Memory limit: 65536 kilobytes
input: standard
output: standard



Dr. Vasechkin wants to paint all numbers from 1 to N in such a way that if number A is divisible by number B, numbers A and B have different colors.

Help Dr. Vasechkin to find such a painting, where the number of the colors used is minimal.

Input
The input contains integer number N ().

Output
Write the number of the colors M in the desired painting in the first line of the output. In the second line of the output write the desired painting of numbers from 1 to N. The used colors should be represented by numbers from 1 to M. If there are several solutions, choose any of them.

Example(s)
sample input
sample output
12
4
1 2 2 3 2 3 2 4 3 3 2 4

=================
