Codeforces Round #563 (Div. 2) C - Ehab and a Special Coloring Problem

You're given an integer n. For every integer i from 2 to n, assign a positive integer ai

such that the following conditions hold:

  • For any pair of integers (i,j)

, if i and j are coprime, ai≠aj

  • .
  • The maximal value of all ai
  • should be minimized (that is, as small as possible).

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

.

Input

The only line contains the integer n

(2≤n≤105

).

Output

Print n−1

integers, a2, a3, …, an (1≤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 3

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

.


思路:模拟一下埃筛就好了

 

#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define Max 105
#include<queue>
int a[105000];
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        int sum=0;
        for(int i=2;i<=n;i++)
        {
            if(a[i]==0)
            {
                sum++;
                for(int j=1;j*i<=n;j++)
                {
                    if(a[i*j]==0) a[i*j]=sum;
                }
            }
        }
        printf("%d",a[2]);
        for(int i=3;i<=n;i++) printf(" %d",a[i]);
        printf("\n");
    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值