CodeForces 776B Sherlock and his girlfriend

Posted

tags:

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


题目链接:​​http://codeforces.com/contest/776/problem/B​​​
题意:有n个宝石,第i个宝石的价格为i+1,现给宝石染色,如果价值x是价值y的素数因子,则不能染相同的颜色
解析:把1e5+1都预处理一遍,然后直接做即可

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <set>
#include <stack>
#include <map>
using namespace std;
const int maxn = 1e5+100;
int vis[maxn];
int main()

int n;
scanf("%d",&n);
memset(vis,0,sizeof(vis));
for(int i=2;i<=1e5;i++)

for(int j=2*i;j<=1e5+1;j+=i)
vis[j] = 1;

if(n<3)

printf("1\\n1");
for(int i=1;i<n;i++)
printf(" 1");

else

printf("2\\n1");
for(int i=2;i<=n;i++)

if(vis[i+1])
printf(" 2");
else
printf(" 1");


puts("");
return 0;


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

CF776B Sherlock and his girlfriend

Codeforces_776B: Sherlock and his girlfriend(素数筛)

sql [从马歇尔选择最高级别的sherlock xmatches] #xmatch #sherlock #pessto #marshall

Sherlock 操作栏更改文本颜色

Sherlock之Instructions指令介绍(Sherlock Version: 7.2.5.1 64-bit)

将 webview 添加到 sherlock 片段中