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 水题.给原序列排序,如果此时合法则直接输出,否则 ...
随机推荐
- Leetcode 258 Add Digits数论
class Solution { public: int addDigits(int num) { ) return num; == ? : num % ; } }; 就是数位根!
- 利用tcpdump分析工具来验证tcp连接的建立和关闭过程
本文要求读者在阅读之前应该对TCP通过三次握手建立和关闭连接有一定的了解,本文并没有详细讲解三次握手,只是通过一个实例对三次握手进行了一下验证. tcp连接的建立和关闭想必大家都已经非常熟悉了!通过三 ...
- 细数 Windows Phone 灭亡的七宗罪(过程很详细,评论很精彩,但主要还是因为太慢了,生态跟不上,太贪了,厂商不愿意推广)
曾梦想仗剑走天涯,看一看世界的繁华 年少的心有些轻狂,如今你四海为家 曾让你心疼的姑娘,如今已悄然无踪影 犹记得上大学攒钱买了第一台智能手机Lumia 520时,下载的第一首歌曲<曾经的你> ...
- Python 函数调用性能记录
之前用 JS 写项目的时候,项目组用的组件模式,一直感觉很不错.最近用 Python 做新项目,项目结构也延续了组件模式.一直没有对函数调用的性能作了解,今天突发奇想测试了一下,写了一些测试代码 首先 ...
- explanatory variable(independent vs dependent)、design matrix
design matrix(设计矩阵) 是统计学上的概念,一般标记为 X,是由一组对象的解释变量(explanatory variables)构成的矩阵. 1. explanatory variabl ...
- WPF 绑定父类属性
原文:WPF 绑定父类属性 1.绑定父控件的属性. <ContextMenu x:Key="ContextMenuColoum"> <MenuItem Heade ...
- 在Winform窗体中使用WPF控件(附源码)
原文:在Winform窗体中使用WPF控件(附源码) 今天是礼拜6,下雨,没有外出,闲暇就写一篇博文讲下如何在Winform中使用WPF控件.原有是我在百度上搜索相关信息无果,遂干脆动手自己实现. W ...
- Window Features 总览
This overview discusses features of windows such as window types, states, size, and position. Window ...
- Win8Metro(C#)数字图像处理--2.18图像平移变换
原文:Win8Metro(C#)数字图像处理--2.18图像平移变换 [函数名称] 图像平移变换函数TranslationProcess(WriteableBitmap src,int x,in ...
- WPF 在一个dll创建一个Window(包含xaml),在另一个dll中再次继承 会出错
https://social.msdn.microsoft.com/Forums/vstudio/en-US/e92390eb-bbfa-42fb-baa9-2286444c0dca/the-comp ...