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,j), if i and j are coprime, ai≠aj
The maximal value of all ai should be minimized (that is, as small as possible).
A pair of integers is called coprime if their greatest common divisor is 1.
input
The only line contains the integer n (2≤n≤105).
output
Print n−1
integers, a2, a3, …, an (1≤ai≤n).
If there are multiple solutions, print any of them.
题意
给你一个数,让你输出长度为n-1的数组,这个数组的起始下标从2开始,使每组任意下标互质的两个数所对应的值都互质。
思路
由于范围在10^5,故可以打素数表,遇到2的倍数打印1,遇到3的倍数打印2,遇到5的倍数打印3...遇到质数的倍数打印该质数在质数表中的位置即可。
//
// Created by hjy on 19-6-4.
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+;
int n;
bool prime(int m)//简单判断素数
{ for(int i=;i<=sqrt(m);i++)
{
if(m%i==)
return false;
}
return true;
}
int result[maxn]={};
void cun()///存入表中
{
int op=;
for(int i=;i<=maxn;i++)
{ if(prime(i))
{
op++;
//cout<<"i="<<i<<endl;
for(int j=i;j<=maxn;j+=i)
{
//cout<<"j="<<j<<endl;
result[j]=op;
//cout<<"result[j]="<<result[j]<<endl; }
}
}
}
int main()
{ int n;
while(cin>>n) {
cun();
for(int i=;i<=n;i++)
cout<<result[i]<<' ';
cout<<endl;
}
return ;
}
Codeforces Round #563 (Div. 2)C的更多相关文章
- Codeforces Round #563 (Div. 2)/CF1174
Codeforces Round #563 (Div. 2)/CF1174 CF1174A Ehab Fails to Be Thanos 其实就是要\(\sum\limits_{i=1}^n a_i ...
- 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 Round #563 (Div. 2) B. Ehab Is an Odd Person
链接:https://codeforces.com/contest/1174/problem/B 题意: You're given an array aa of length nn. You can ...
- Codeforces Round #563 (Div. 2) A. Ehab Fails to Be Thanos
链接:https://codeforces.com/contest/1174/problem/A 题意: You're given an array aa of length 2n2n. Is it ...
- Codeforces Round #563 (Div. 2)B
B.Ehab Is an Odd Person 题目链接:http://codeforces.com/contest/1174/problem/B 题目 You’re given an array a ...
- Codeforces Round #563 (Div. 2)A
A. Ehab Fails to Be Thanos 题目链接:http://codeforces.com/contest/1174/problem/A 题目 You’re given an arra ...
- Codeforces Round #563 (Div. 2) E. Ehab and the Expected GCD Problem
https://codeforces.com/contest/1174/problem/E dp 好题 *(if 满足条件) 满足条件 *1 不满足条件 *0 ///这代码虽然写着方便,但是常数有点大 ...
- Codeforces Round #563 (Div. 2) F. Ehab and the Big Finale
后续: 点分治标程 使用father数组 比使用vis数组优秀(不需要对vis初始化) https://codeforces.com/problemset/problem/1174/F https:/ ...
- Codeforces Round 563 (Div. 2) 题解
自己开了场镜像玩. 前三题大水题.D有点意思.E完全不会.F被题意杀了……然而还是不会. 不过看过(且看懂)了官方题解,所以这里是六题题解齐全的. A 水题.给原序列排序,如果此时合法则直接输出,否则 ...
随机推荐
- 简明Python3教程 13.面向对象编程
简介 (注: OOP代表面向对象编程,OO代表面向对象,以后全部使用英文缩写) 迄今为止我们编写的所有程序都是围绕函数创建的,函数即操纵数据的语句块.这称作面向过程编程. 除此之外还有另一种组织程序的 ...
- python 教程 第五章、 函数
第五章. 函数 定义语句后面要加冒号 1) 定义函数 def sayHello(): print 'Hello World!' sayHello() 2) 变量作用域 LEGB原则 L本地 ...
- delphi的拖拽功能实现
惭愧,编了这么多年程序,还没用过拖拽功能 这次同事要实现图标互换的功能,让我帮忙看一下,于是趁机研究了一下拖拽事件,发现还是比较简单的 参考了http://topic.csdn.net/u/20081 ...
- aspx页面@Page指令解析
@Page指令位于每个ASP.NET页面的顶部,告诉ASP.NET这个具体页面使用什么属性,以及该页面继承的用户控件.ASP.NET页面@Page指令属性有:AspCompat.Async.Async ...
- comtextMenu 如何正确的响应MouseLeave事件
今天给菜单加上这个事件,发现弹出菜单后 鼠标怎么动都不会触发 mouseLeave事件 解决方法是 在菜单loaded事件中,利用visualTreeHelper 访问他内部的border控件,把这个 ...
- DateTime格式转换结果
Console.WriteLine(string.Format("ToLongDateString:{0}", DateTime.Now.ToLongDateString())); ...
- System.InvalidOperationException: 未在本地计算机上注册“Microsoft.ACE.OLEDB.12.0”提供程序。
今天在写导入Excel表格的代码,运行时却报异常,异常信息: System.InvalidOperationException: 未在本地计算机上注册“Microsoft.ACE.OLEDB.12.0 ...
- 传入字典的模型项的类型为“System.Boolean”,但此字典需要类型“InternalCRM.EntityIACrm.Template”的模型项。
“/”应用程序中的服务器错误. 传入字典的模型项的类型为“System.Boolean”,但此字典需要类型“InternalCRM.EntityIACrm.Template”的模型项. 说明: 执行当 ...
- tbox的项目:vm86(汇编语言虚拟机),tbox(类似dlib),gbox(c语言实现的多平台图形库)
https://github.com/tboox/tbox GBOX是一个用c语言实现的多平台图形库,支持windows.linux.mac.ios.android以及其他嵌入式系统. 现在这个项目, ...
- Aria2在Windows上如何安装配置使用
一.下载所需的软件 二.安装与使用 三.Aria2的额外内容 四.Aria2的使用 五.Aria2与其它插件配合使用 一.下载所需的软件 可以从一下地址获取最新版本 GitHub: https://g ...