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< ...
随机推荐
- numpy包学习笔记
导入 import numpy as np argsort() numpy中的排序函数 返回的是数组中从小到大的索引值 from numpy import * test=[5,2,3,4,1] pri ...
- mysql如何让两个字段数据都不能重复?
目录 场景 任务(需求) 行动(解决方案) 方案1:从代码层面解决(正确方案) 方案2:设置成两个唯一索引(正确方案) 方案3:删掉中间表,把从表的主键作为主表的外键,并将外键设置成唯一索引(正确方案 ...
- VS中关于数据库的操作
1.数据库迁移 第一步: 第二步: 在窗口中选择项目中的EntitiyFramwork项目(与数据库连接的文件集) 第三步: 输入update-database 二:数据对比 第一步: 第二步:选择需 ...
- Burp Suite Professional 针对APP抓包篡改数据提交【安全】
Burp Suite 是用于攻击web 应用程序的集成平台,包含了许多工具.Burp Suite为这些工具设计了许多接口,以加快攻击应用程序的过程.所有工具都共享一个请求,并能处理对应的HTTP 消息 ...
- 2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛 Banana
签到题 50的规模,随便搞搞都能过,用stl的string的搜索直接做了 #include <bits/stdc++.h> using namespace std; typedef lon ...
- linux 配置compoer
配置默认php 删除 rm -f /usr/bin/php 改到php7.3版本的composer /bin/php /usr/bin/php 多版本支持 配置php7专用composer70 cd ...
- 一些java基础知识的备忘
接口和抽象类的区别是什么? 接口的方法默认是 public,所有方法在接口中不能有实现(Java 8 开始接口方法可以有默认实现),而抽象类可以有非抽象的方法. 接口中除了static.final变量 ...
- LED And Incandescent, Who Is Suitable For Holiday Lighting?
Fast-fire advantages of LED lighting: Eco-friendly-LEDs are not made of toxic chemicals, such as mer ...
- 机器学习作业(七)非监督学习——Matlab实现
题目下载[传送门] 第1题 简述:实现K-means聚类,并应用到图像压缩上. 第1步:实现kMeansInitCentroids函数,初始化聚类中心: function centroids = kM ...
- JFinalSwagger插件
个人博客 地址:http://www.wenhaofan.com/article/20190304101839 jfinal使用swagger的极简插件 码云地址:https://gitee.com/ ...