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< ...
随机推荐
- 文件流之输入输出(类似于freopen重定向)
利用标准文件操作函数进行数据的输入输出,所用函数均在stdio.h中,类似于freopen重定向文件. 该方法的思路是: (1)建立文件指针 (2)打开文件,将文件指针指向打开的文件,并决定打开的文件 ...
- lasso-ridge
线性回归 线性回归很简单,用线性函数拟合数据,用 mean square error (mse) 计算损失(cost),然后用梯度下降法找到一组使 mse 最小的权重. lasso 回归和岭回归(ri ...
- python的for循环的神奇之处
python的for循环太神奇了: 你可以编写这样的语句: for i in range(10) : j= i**2 print(j) 你也可以编写这样的语句: with open('/path/to ...
- CF1205E Expected Value Again
题意 题意翻译 对于一个字符串\(s\),我们定义其美丽值\(f(s)\)为满足下列两个条件的正整数\(i\)的个数: \(1\leq i<|s|\) \(s\)长度为\(i\)的前缀与后缀相等 ...
- 从零开始学 Java - 搭建 Spring MVC 记录云创的日子 第一章
2017年11月29日 来到新项目,需要用到Spring MVC ,那么我就开始记录我这次的学习. Spring MVC 框架是围绕一个 DispatcherServlet 来设计的,这个 Servl ...
- http断点续传Range与Content-Range
今天用别人封装的libcurl库下载文件,发现下载下来的文件总是缺少头两个字节,用以下配置启用HTTP头信息打印后发现原来是设置了断点续传位置的原因 curl_easy_setopt(m_pCurl, ...
- vue常用插件之视频播放(rtmp m3u8)
vue-video-player(5.0.2) 最近我的项目做了一个监控视屏的显示,后台提供的视屏格式是rtmp 后来又改为m3u8,没成功,原因是占用内存过大,所以取消了这种方式 一.安装 npm ...
- Codeforce 567A - Lineland Mail
All cities of Lineland are located on the Ox coordinate axis. Thus, each city is associated with its ...
- SVM-支持向量机(一)线性SVM分类
SVM-支持向量机 SVM(Support Vector Machine)-支持向量机,是一个功能非常强大的机器学习模型,可以处理线性与非线性的分类.回归,甚至是异常检测.它也是机器学习中非常热门的算 ...
- TODO:rds数据库实例
rds数据库实例怎么创建的 rds数据库实例高可用是怎么实现的 rds备份是怎么实现的 参考: https://www.cnblogs.com/jackyzzy/p/7384355.html http ...