F. Kate and imperfection

F. Kate and imperfection

time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output

Kate has a set S of n integers {1,…,n}.

She thinks that imperfection of a subset M⊆S is equal to the maximum of gcd(a,b) over all pairs (a,b) such that both a and b are in M and a≠b.

Kate is a very neat girl and for each k∈{2,…,n} she wants to find a subset that has the smallest imperfection among all subsets in S of size k. There can be more than one subset with the smallest imperfection and the same size, but you don’t need to worry about it. Kate wants to find all the subsets herself, but she needs your help to find the smallest possible imperfection for each size k, will name it Ik.

Please, help Kate to find I2, I3, …, In.

Input
The first and only line in the input consists of only one integer n (2≤n≤5⋅105) — the size of the given set S.

Output
Output contains only one line that includes n−1 integers: I2, I3, …, In.
原题连接

**题意:**给出一个数n,输出n-1个数,第i个数是从1到n中取i+1个数,使其最大的gcd(a,b)最小
**思路:**先把素数放进去,然后再放素数2,然后放素数3,注意,每当放入一个合数的时候该合数的所有因子一定已经放入,所以该合数的贡献是自己的最大公因数,把贡献小的先放入,后放入大的,用筛法把每个数的最大最大公约数算出来,然后排序就是答案。


```cpp
#include<stdio.h>
#include<algorithm>
using namespace std;
int ans[500010],maxy[500010];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		for(int j=2*i;j<=n;j+=i){
			maxy[j]=i;
		}
		ans[i]=maxy[i];
	}
	sort(ans+2,ans+n+1);
	for(int i=2;i<=n;i++){
		printf("%d ",ans[i]);
	}
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值