Ehab and a Special Coloring Problem
You're given an integer nn. For every integer ii from 22 to nn, assign a positive integer aiai such that the following conditions hold:
- For any pair of integers (i,j)(i,j), if ii and jj are coprime, ai≠ajai≠aj.
- The maximal value of all aiai should be minimized (that is, as small as possible).
A pair of integers is called coprime if their greatest common divisor is 11.
The only line contains the integer nn (2≤n≤1052≤n≤105).
Print n−1n−1 integers, a2a2, a3a3, ……, anan (1≤ai≤n1≤ai≤n).
If there are multiple solutions, print any of them.
4
1 2 1
3
2 1
In the first example, notice that 33 and 44 are coprime, so a3≠a4a3≠a4. Also, notice that a=[1,2,3]a=[1,2,3] satisfies the first condition, but it's not a correct answer because its maximal value is 33.
素数筛选:
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <numeric>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define mod 998244353
using namespace std;
int dir[][] = { {,},{,-},{-,},{,} };
const int maxn = 1e5 + ; int main()
{
int n;
cin >> n;
int cnt=;
vector<int> a(maxn);
vector<bool> b(maxn);
for (int i = ; i <= n; i++)
{
if (!b[i])
{
a[i] = ++cnt;
for (int j = i + i; j <= n; j += i)
b[j] = , a[j] = a[i];
}
} for (int i = ; i <= n; i++)
cout << a[i] << " ";
return ;
}
Ehab and a Special Coloring Problem的更多相关文章
- Codeforces Round #563 (Div. 2) C. Ehab and a Special Coloring Problem
链接:https://codeforces.com/contest/1174/problem/C 题意: You're given an integer nn. For every integer i ...
- Codeforces 1174C Ehab and a Special Coloring Problem
题目链接:http://codeforces.com/problemset/problem/1174/C 题意:给你一个n,要你填充 下标由2 ~ n 的数组ai,要求下标互质的俩个数不能相等,并且数 ...
- CF1174C Ehab and a Special Coloring Problem(数论)
做法 与\(x\)互质的数填不同的数,把有向关系表示出来,发现边数是不能承受的 反过来想,成倍数关系填相同的数,把这些数想象成一条链,而这条链开始的数一定是质数,\(\sum\limits_{prim ...
- Codeforces 1088E Ehab and a component choosing problem
Ehab and a component choosing problem 如果有多个连接件那么这几个连接件一定是一样大的, 所以我们先找到值最大的连通块这个肯定是分数的答案. dp[ i ]表示对于 ...
- Codeforces Round #525 (Div. 2)E. Ehab and a component choosing problem
E. Ehab and a component choosing problem 题目链接:https://codeforces.com/contest/1088/problem/E 题意: 给出一个 ...
- Codeforces Round #525 (Div. 2)D. Ehab and another another xor problem
D. Ehab and another another xor problem 题目链接:https://codeforces.com/contest/1088/problem/D Descripti ...
- [E. Ehab's REAL Number Theory Problem](https://codeforces.com/contest/1325/problem/E) 数论+图论 求最小环
E. Ehab's REAL Number Theory Problem 数论+图论 求最小环 题目大意: 给你一个n大小的数列,数列里的每一个元素满足以下要求: 数据范围是:\(1<=a_i& ...
- 题解-Ehab's REAL Number Theory Problem
Ehab's REAL Number Theory Problem 前置知识 质数 分解质因数 无向无权图最小环<讲> Ehab's REAL Number Theory Problem/ ...
- codeforces#1157D. Ehab and the Expected XOR Problem(构造)
题目链接: http://codeforces.com/contest/1174/problem/D 题意: 构造一个序列,满足以下条件 他的所有子段的异或值不等于$x$ $1 \le a_i< ...
随机推荐
- 关于MySQL数据库中null的那些事
在mysql数据库中,null是一个经常出现的情况,关于mysql中的null,有哪些注意事项呢?下面简单总结归纳下,后续会不断补充. 1. is null 首先判断数据库中某一列的值是否为null, ...
- Wannafly Camp 2020 Day 2D 卡拉巴什的字符串 - 后缀自动机
动态维护任意两个后缀的lcp集合的mex,支持在串末尾追加字符. Solution 考虑在 SAM 上求两个后缀的 LCP 的过程,无非就是找它们在 fail 树上的 LCA,那么 LCP 长度就是这 ...
- 0级搭建类006-Oracle Solaris 安装 (10.13) 公开
项目文档引子系列是根据项目原型,制作的测试实验文档,目的是为了提升项目过程中的实际动手能力,打造精品文档AskScuti. 项目文档引子系列目前不对外发布,仅作为博客记录.如学员在实际工作过程中需提前 ...
- Robot Framework选择定位option类型下拉框
页面下拉框一般有两种类型,一种是div标签的,一种是option类型的,比如: div标签类型则可以通过定位进行元素点击去选择对应的枚举参数则可,而option类型的下拉选项则通过Selenium2L ...
- spring框架中用到了哪些设计模式
1.代理模式:在AOP和remoting中被用的比较多 2.单例模式:在spring配置文件中定义的bean默认为单例模式 3.模板方法模式:解决代码重复问题 4.前端控制器模式:spring提供了D ...
- Spring IoC详解
Spring IoC详解 1. 控制反转 控制反转是一种通过描述(XML或者注解)并通过第三方去产生或获取特定对象的方式.在Spring中实现控制反转的是IoC容器,其实现方法是依赖注入(Depend ...
- docker-储存持久化
docker容器不适合存放数据,重要的数据要用外部卷存储,容器可以挂载真实机目录或者共享存储为卷 储存卷映射 docker run -itd -v 真实机目录:容器目录 镜像:标签 可以做一台nfs服 ...
- @HystrixCommand 不能被导包
添加pom文件 <dependency> <groupId>com.netflix.hystrix</groupId> <artifactId>hy ...
- vue 报错碰到的一些问题及其规范
报错信息:Expected error to be handled(需要处理的错误) 这是因为回调函数里面的参数error没有运用到,所以可以不设置参数,或者在回调函数内console.log(err ...
- (转)git fetch + merge 和 git pull 的区别
转自:http://blog.csdn.net/a19881029/article/details/42245955 Git fetch和git pull都可以用来更新本地库,它们之间有什么区别呢? ...