CF1174C. Ehab and a Special Coloring Problem 质因子|互质问题

13 篇文章 0 订阅
10 篇文章 0 订阅

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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, ai≠ajai≠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 (2≤n≤1052≤n≤105).

Output

Print n−1n−1 integers, a2a2, a3a3, ……, anan (1≤ai≤n1≤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 a3≠a4a3≠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.

 

咸鱼了很久,被队友推荐了个题目,发现确实是个很有意思的题。在此感谢队友!

题意:就是说用输入一个n,让我们构造一个数组,使得这个数组满足两个条件:

1.这个数组的任意下标(i,j)如果ij互质,那么他们对应的元素值应当不同

2.要使数组中的没个元素都尽可能的小

输出2~n下标下的元素值

 

分析:既然牵扯到互质,那么我们发现其中所有的互质对下标对应的元素都要不同,那么也就是小于n的所有的质数所对应的元素值要两两不同,所以也就是说所有的质数要从最小值依次递增才能让其中任选两个质数的下标下的元素才能都与对方不同。

那么这时质数下标对应的元素,那么非质数下标呢?

我们发现非质数有可能与某些质数互质,那么也需要保证二者之间对应元素不同的问题,所以在这里,不妨考虑非质数的因子可能跟质数有关,就想素数筛选法,所有的非质数都是由其因子拓展而来,而其因子必定不与其互质,所以不妨就用因子对应的元素值,从而保证了非质数下标下的元素的互质问题,由于这个下标有可能还和很多质数互质,所以不妨就获取其质因子的对应元素赋予给非质数元素。

所以一切都回到了质数下标下的赋值问题,为了满足条件2,我们需要从1开始为质数下标下的元素开始赋值。

整个算法可以参照质数筛选法解决。

code:



#include<bits/stdc++.h>
using namespace std;
const int maxn = (int)(1e5+10);
int a[maxn],pri[maxn],cnt;
bool bok[maxn]; 
int main(){
	int n;
	scanf("%d",&n);
	for(int i=2;i<=n;i++){
		if(!bok[i]){
			a[i] = ++cnt;
			for(int j=i+i;j<=n;j+=i)bok[j] = 1,a[j] = a[i];
		}		
	}
	
	for(int i=2;i<=n;i++){
		printf("%d",a[i]);
		if(i==n)putchar('\n');
		else putchar(' ');	
	}
		
	return 0;
} 

 

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值