Codeforces Round #563 (Div. 2)C. Ehab and a Special Coloring Problem

原文链接:传送门
思路:素数筛
代码:

 1 #include"iostream"
 2 #include"algorithm"
 3 #include"cstring"
 4 using namespace std;
 5 long long  a[2000006],n;
 6 int main(){
 7     cin>>n;
 8     long long  flag = 1;
 9     memset(a,0,sizeof(a));
10     for(int i=2;i<=n;i++){
11         if(a[i]==0){
12             a[i]=flag;
13             for(int j=i*2;j<=n;j+=i)
14              if(a[j]==0)
15               a[j]=flag;
16               flag++;
17         }
18         cout<<a[i];
19         if(i<n)
20         cout<<" ";
21     }
22     return 0;
23 }

原文地址:https://www.cnblogs.com/huangdf/p/12222897.html

时间: 2024-11-09 03:07:53

Codeforces Round #563 (Div. 2)C. Ehab and a Special Coloring Problem的相关文章

Codeforces Round #563 (Div. 2)B;Ehab Is an Odd Person

原文链接:任意门 题目大意:给你一组数,让你交换两个数的位置,让它们的和为奇数,且使其交换后,顺序满足最小字典序列.思路:这就是一道狗题,看代码,你就会******了,只需要sort排序.代码: 1 #include"iostream" 2 #include"algorithm" 3 #include"cstdio" 4 #include"cstring" 5 long long a[10000006],n,js=0,os=0

Codeforces Round #563 (Div. 2)C

C. Ehab and a Special Coloring Problem 题目链接:http://codeforces.com/contest/1174/problem/C 题目 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,

Codeforces Round #563 (Div. 2)/Codeforces1174

CF1174A Ehab Fails to Be Thanos 其实就是要\(\sum\limits_{i=1}^n a_i\)与\(\sum\limits_{n+1}^{2n}a_i\)差值最大,排一下序就好了 CF1174B Ehab Is an Odd Person 一个显然的性质就是如果至少有一个奇数和一个偶数,那么是可以随意调整的,也就是升序排序 否则不可以进行任何操作 CF1174C Ehab and a Special Coloring Problem 把每个质数预处理出来,\(x

Codeforces Round #563 (Div. 2) D、Ehab and the Expected XOR Problem

D. Ehab and the Expected XOR Problem Given two integers n and x, construct an array that satisfies the following conditions: for any element ai in the array, 1≤ai<2^n there is no non-empty subsegment with bitwise XOR equal to 0 or x, its length l sho

Codeforces Round #525 (Div. 2)A. Ehab and another construction problem

A. Ehab and another construction problem 题目链接:https://codeforc.es/contest/1088/problem/A 题意: 给出一个x,找出这样的a,b满足:1<=a,b<=x,并且a%b=0,a/b<x,a*b>x. 题解: 赛后发现,除开x=1的情况,其它情况a=b=x就可以满足条件了... 但还是附上比赛时候的代码吧... #include <bits/stdc++.h> using namespace

Codeforces Round #563 (Div. 2)

CF 题目链接:https://codeforces.com/contest/1174 总结 ABC都比较水,27分钟写完了,但是D题想偏了,一直WA,AC代码确实太巧妙了. A题 #include<bits/stdc++.h> using namespace std; #define ll long long #define N 100050 int n,sum1,sum2,a[N]; template<typename T>void read(T&x) { ll k=0

Codeforces Round 563 (Div. 2) 题解

自己开了场镜像玩. 前三题大水题.D有点意思.E完全不会.F被题意杀了……然而还是不会. 不过看过(且看懂)了官方题解,所以这里是六题题解齐全的. A 水题.给原序列排序,如果此时合法则直接输出,否则说明所有数相同,一定无解. 时间复杂度 $O(n\log n)$. #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> PII; const int maxn=

Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem F (Codeforces 831F) - 数论 - 暴力

Vladimir wants to modernize partitions in his office. To make the office more comfortable he decided to remove a partition and plant several bamboos in a row. He thinks it would be nice if there are n bamboos in a row, and the i-th from the left is a

Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 831D) - 贪心 - 二分答案

There are n people and k keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebo