You are given a sequence of integers a1,a2,…,an. You need to paint elements in colors, so that:

  • If we consider any color, all elements of this color must be divisible by the minimal element of this color.
  • The number of used colors must be minimized.

For example, it's fine to paint elements [40,10,60]in a single color, because they are all divisible by 10. You can use any color an arbitrary amount of times (in particular, it is allowed to use a color only once). The elements painted in one color do not need to be consecutive.

For example, if a=[6,2,3,4,12]then two colors are required: let's paint 6, 3 and 12 in the first color (6, 3 and 12 are divisible by 3) and paint 2 and 4 in the second color (2 and 4 are divisible by 2). For example, if a=[10,7,15]then 3 colors are required (we can simply paint each element in an unique color).

Input

The first line contains an integer n (1≤n≤100), where n is the length of the given sequence.

The second line contains n integers a1,a2,…,an (1≤ai≤100). These numbers can contain duplicates.

Output

Print the minimal number of colors to paint all the given numbers in a valid way.

Examples
input
6
10 2 3 5 4 2
output
3
input
4
100 100 100 100
output
1
input
8
7 6 5 4 3 2 2 3
output
4
Note

In the first example, one possible way to paint the elements in 3 colors is:

  • paint in the first color the elements: a1=10 and a4=5,
  • paint in the second color the element a3=3,
  • paint in the third color the elements: a2=2, a5=4 and a6=2.

In the second example, you can use one color to paint all the elements.

In the third example, one possible way to paint the elements in 4 colors is:

  • paint in the first color the elements: a4=4 a6=2 and a7=2,
  • paint in the second color the elements: a2=6, a5=3 and a8=3,
  • paint in the third color the element a3=5,
  • paint in the fourth color the element a1=7.

题意解释:输入n个数,对一个数进行涂色时,被涂色的数的倍数也会被涂色。输出最少涂几次可以涂完所有的数

思路和筛法是一样的,从小的往大的筛,直到筛完为止。

#include <bits/stdc++.h>
using namespace std;
int a[];
int main()
{
int n;
cin>>n;
for(int i=;i<n;++i)
{
int t;
cin>>t;
a[t]=t;
}
int ans=;
for(int i=;i<=;++i)
{
if(a[i])
{
for(int j=i;j<=;j+=i)
{
a[j]=;
}
ans++;
}
}
cout<<ans;
return ;
}

CF1209A Paint the Numbers的更多相关文章

  1. Codeforces Round #584 A. Paint the Numbers

    链接: https://codeforces.com/contest/1209/problem/A 题意: You are given a sequence of integers a1,a2,-,a ...

  2. The Unreasonable Effectiveness of Recurrent Neural Networks (RNN)

    http://karpathy.github.io/2015/05/21/rnn-effectiveness/ There’s something magical about Recurrent Ne ...

  3. Codeforces Round #584

    传送门 A. Paint the Numbers 签到. Code #include <bits/stdc++.h> using namespace std; typedef long l ...

  4. Codeforces Round #584 - Dasha Code Championship - Elimination Round (rated, open for everyone, Div. 1 + Div. 2)

    怎么老是垫底啊. 不高兴. 似乎 A 掉一道题总比别人慢一些. A. Paint the Numbers 贪心,从小到大枚举,如果没有被涂色,就新增一个颜色把自己和倍数都涂上. #include< ...

  5. gym101090 I Painting the natural numbers

    题目地址:http://codeforces.com/gym/101090 题目: The H&H company currently develops AI (artificial inte ...

  6. Codeforces 196 C. Paint Tree

    分治.选最左上的点分给根.剩下的极角排序后递归 C. Paint Tree time limit per test 2 seconds memory limit per test 256 megaby ...

  7. [CodeForces - 197E] E - Paint Tree

    E - Paint Tree You are given a tree with n vertexes and n points on a plane, no three points lie on ...

  8. Codeforces Round #124 (Div. 1) C. Paint Tree(极角排序)

    C. Paint Tree time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  9. Codeforces Round #597 (Div. 2) A. Good ol' Numbers Coloring

    链接: https://codeforces.com/contest/1245/problem/A 题意: Consider the set of all nonnegative integers: ...

随机推荐

  1. 吴裕雄--天生自然HADOOP操作实验学习笔记:Wor的Count程序的编写

    实验目的 理解mapreduce的工作原理 理解Partitioner的书写方法 理解GroupingComparator的书写方法 实验原理 我们已经学习了hadoop的大部分基础知识,剩下的就是利 ...

  2. jmeter分布式linux负载机,windows主控机

    1.将参数化文件上传到linux服务器,放在linux上jmeter的bin路径下 2.设置server.rmi.ssl.disable=true 分别修改主控机和负载机的jmeter.propert ...

  3. stringstream常见用法介绍

    1 概述 <sstream> 定义了三个类:istringstream.ostringstream 和 stringstream,分别用来进行流的输入.输出和输入输出操作.本文以 stri ...

  4. Python学习第八课——函数

    python函数(def) def test(x): # x为形参 y = x + 20 return y # def:定义函数的关键字 # test:函数名 # ():内定义参数 # x+=1:代码 ...

  5. MySQL更新时间

    Mysql时间加减函数为date_add().date_sub()定义和用法DATE_ADD() 函数向日期添加指定的时间间隔.DATE_SUB() 函数向日期减少指定的时间间隔.语法DATE_ADD ...

  6. Linux设备树学习

    1.概念 设备树用于实现驱动代码与设备信息相分离.驱动代码只负责处理驱动的逻辑而关于设备的具体信息存放到设备树文件中.(dts文件,编译后为dtb文件).一个dts文件对应一个ARM的machine, ...

  7. 4.2 Scikit-Learn简介(机器学习篇)

    目录 第四章 机器学习 4.1 机器学习简介 4.1.1 机器学习分类 4.2 Scikit-Learn简介 4.2.1 Scikit-Learn的数据表示 4.2.2 Scikit-Learn的评估 ...

  8. Day2-J-逃离迷宫-HDU-1728

    给定一个m × n (m行, n列)的迷宫,迷宫中有两个位置,gloria想从迷宫的一个位置走到另外一个位置,当然迷宫中有些地方是空地,gloria可以穿越,有些地方是障碍,她必须绕行,从迷宫的一个位 ...

  9. DeprecationWarning:'open()' is deprecated in mongoose>=4.11.0,use 'openUri()' instead or set the 'useMongoClient' option if using 'connect()' or 'createConnection'

    mongoose.connect('mongodb://localhost/test');报错:(node:2752) DeprecationWarning: `open()` is deprecat ...

  10. CSS -- 盒子模型 margin 的特点

    margin在使用过程中具有如下的两个特点: 1.垂直外边距塌陷 --给子元素设置margin-top的时候,如果父元素也随着margin-top改变位置 解决方式: 给父元素设置边框 给父元素设置o ...