CF776B Sherlock and his girlfriend

Posted kafuuchino

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CF776B Sherlock and his girlfriend相关的知识,希望对你有一定的参考价值。

CF776B Sherlock and his girlfriend

一个数和它的质因数不能同色。

素数的约数只有本身和1。

显然所有素数都可以染同色,合数同理。

欧拉筛一筛。

注意特判n<3的情况。

技术分享图片
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #define re register
 5 using namespace std;
 6 #define N 100002
 7 int n,v[N],pri[N],cct;bool is[N];
 8 int main(){
 9     for(int i=2;i<N;++i){
10         if(!v[i]) is[v[i]=pri[++cct]=i]=1;
11         for(int j=1;j<=cct;++j){
12             if(pri[j]>i||pri[j]*i>=N) break;
13             v[pri[j]*i]=pri[j];
14         }
15     }scanf("%d",&n);
16     if(n<3){
17         puts("1");
18         for(int i=1;i<=n;++i) printf("1 ");
19     }else{
20         puts("2");
21         for(re int i=2;i<=n+1;++i) printf("%d ",(!is[i])+1);
22     }
23     return 0;
24 }
View Code

 

以上是关于CF776B Sherlock and his girlfriend的主要内容,如果未能解决你的问题,请参考以下文章

CodeForces 776B Sherlock and his girlfriend

一本通1623Sherlock and His Girlfriend

Codeforces_776B: Sherlock and his girlfriend(素数筛)

CF1179B Tolik and His Uncle

CF-1362B. Johnny and His Hobbies

CF-1362B. Johnny and His Hobbies