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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. Codeforces Round #563 (Div. 2)A

    A. Ehab Fails to Be Thanos 题目链接:http://codeforces.com/contest/1174/problem/A 题目 You’re given an arra ...

  7. Codeforces Round #563 (Div. 2) E. Ehab and the Expected GCD Problem

    https://codeforces.com/contest/1174/problem/E dp 好题 *(if 满足条件) 满足条件 *1 不满足条件 *0 ///这代码虽然写着方便,但是常数有点大 ...

  8. Codeforces Round #563 (Div. 2) F. Ehab and the Big Finale

    后续: 点分治标程 使用father数组 比使用vis数组优秀(不需要对vis初始化) https://codeforces.com/problemset/problem/1174/F https:/ ...

  9. Codeforces Round 563 (Div. 2) 题解

    自己开了场镜像玩. 前三题大水题.D有点意思.E完全不会.F被题意杀了……然而还是不会. 不过看过(且看懂)了官方题解,所以这里是六题题解齐全的. A 水题.给原序列排序,如果此时合法则直接输出,否则 ...

随机推荐

  1. AI2XAML's Bug

    原文:AI2XAML's Bug My picture is like this: I use Adobe Illustator CS to draw the outline of that, I s ...

  2. 微博地址url(id)与mid的相互转换

    关键字:新浪 微博 url id mid 互相转换地址:http://www.cnblogs.com/txw1958/archive/2012/12/07/weibo-id-to-mid.html 通 ...

  3. .NET内置的Ajax工作原理

    在期望不执行回发(postback)而从客户端运行服务器代码的情况下,可以使用ClientScriptManager类来调用客户端回调(callback).这称为对服务器执行带外回调.在客户端回调中, ...

  4. 用WPF实现打印及打印预览

    原文:用WPF实现打印及打印预览 应该说,WPF极大地简化了我们的打印输出工作,想过去使用VC++做开发的时候,打印及预览可是一件极麻烦的事情,而现在我不会再使用C++来做Windows的桌面应用了- ...

  5. WPF范围选择控件(RangeSelector)

    原文:WPF范围选择控件(RangeSelector) 版权声明:本文为博主原创文章,转载请注明作者和出处 https://blog.csdn.net/ZZZWWWPPP11199988899/art ...

  6. 从零开始学习 asp.net core 2.1 web api 后端api基础框架(三)-创建Data Transfer Object

    原文:从零开始学习 asp.net core 2.1 web api 后端api基础框架(三)-创建Data Transfer Object 版权声明:本文为博主原创文章,未经博主允许不得转载. ht ...

  7. html5 模糊匹配搜索框

    使用bootstrap3-typeahead.js 文件在这里 引用: <script type="text/javascript" src="@Url.Conte ...

  8. ASP .NET Controller返回类型

    返回类型 return View(model); 即返回htmlreturn Json("String"); 返回Json格式的数据return File(new byte[] { ...

  9. [PHP7.0-PHP7.2]的新特性和新变更

    php7发布已经升级到7.2.里面发生了很多的变化.本文整理php7.0至php7.2的新特性和一些变化. 参考资料: http://php.net/manual/zh/migration70.new ...

  10. Post utf-8 请求

    /// <summary> /// POST请求与获取结果 /// </summary> public static string HttpPost(string Url, s ...