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");
    }
}

 

全部评论

相关推荐

点赞 评论 收藏
分享
昨天 12:10
已编辑
牛客_产品运营部_运营
点赞 评论 收藏
分享
会飞的猿:我看你想进大厂,我给你总结一下学习路线吧,java语言方面常规八股要熟,那些java的集合,重点背hashmap八股吧,jvm类加载机制,运行时分区,垃圾回收算法,垃圾回收器CMS、G1这些,各种乐观锁悲观锁,线程安全,threadlocal这些。在进阶一些的比如jvm参数,内存溢出泄漏排查,jvm调优。我这里说的只是冰山一角,详细八股可以去网上找,这不用去买,都免费资源。mysql、redis可以去看小林coding,我看你简历上写了,你一定要熟,什么底层b+树、索引结构、innodb、mvcc、undo log、redo log、行级锁表级锁,这些东西高频出现,如果面试官问我这些我都能笑出来。消息队列rabbitmq也好kafka也好,学一种就行,什么分区啊副本啊确认机制啊怎么保证不重复消费、怎么保证消息不丢失这些基本的一定要会,进阶一点的比如LEO、高水位线、kafka和rocketmq底层零拷贝的区别等等。计算机网络和操作系统既然你是科班应该理解起来问题不大,去看小林coding这两块吧,深度够了。spring boot的八股好好看看吧,一般字节腾讯不这么问,其他的java大厂挺爱问的,什么循环依赖啥的去网上看看。数据结构的话科班应该问题不大,多去力扣集中突击刷题吧。项目的话其实说白了还是结合八股来,想一想你写的这些技术会给你挖什么坑。除此之外,还有场景题、rpc、设计模式、linux命令、ddd等。不会的就别往简历上写了,虽然技术栈很多的话好看些,但背起来确实累。总结一下,多去实习吧,多跳槽,直到跳到一个不错的中厂做跳板,这是一条可行的进大厂的路线。另外,只想找个小厂的工作的话,没必要全都照这些准备,太累了,重点放在框架的使用和一些基础八股吧。大致路线就这样,没啥太多难度,就是量大,你能达到什么高度取决于你对自己多狠,祝好。
点赞 评论 收藏
分享
02-18 17:30
腾讯_TEG_技术
多刷**&nbsp;背八股&nbsp;刷面经&nbsp;项目话术准备好&nbsp;不会差的!!!后台看到好多小伙伴们都出现其中一个环节的错误,,,可惜了抓紧机会吧&nbsp;有的是hc&nbsp;但缺的就是稍微用心的人
野猪不是猪🐗:多刷星星,背八股背话术,真的能过你们?对一个个没实习过的学生狂问场景题设计题和底层深挖,别以为我不知道一边说缺人还一边各种kpi面
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务