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. Windows驱动开发-IRP结构体

    IRP的全名是I/O Request Package,即输入输出请求包,它是Windows内核中的一种非常重要的数据结构. 上层应用程序与底层驱动程序通信时,应用程序会发出I/O请求,操作系统将相应的 ...

  2. tcp/ip协议学习笔记一

    一. 简述 以前在学校学习计算机网络的时候学习多是网络7层模型OSI,了解了一些基本的计算机网络概念和协议通信格式,但是一直没弄明白其中的原理,包括各层之间的关系,应用,还有一些常见的令牌环网到底是什 ...

  3. 防火墙、WAF、IPS、IDS都是什么

    防火墙 (Firewall) 别名防护墙,于1993发明并引入国际互联网. 他是一项信息安全的防护系统,依照特定的规则,允许或是限制传输的数据通过.在网络中,所谓的防火墙是指一种将内网和外网分开的方法 ...

  4. partialview 用法

    using  MvcApplication1.Models; @model MvcApplication1.Models.UserInfoModel @{     ViewBag.Title = &q ...

  5. kali打开networkmanager

    有时候可能在用网卡时,或者是其他情况下关闭了networkmanager,而要管理网络这个又是必须的,需要我们手动打开. 没有网络管理器是这样的: 有管理器是这样的: 不多废话了,用命令/etc/in ...

  6. 吴裕雄--天生自然JAVAIO操作学习笔记:内存操作流、管道流与打印流操作

    import java.io.* ; class Send implements Runnable{ // 线程类 private PipedOutputStream pos = null ; // ...

  7. Mybatis注解开发单表CRUD

    Mybatis注解开发单表CRUD mybatis注解开发和xml开发不可兼容,要么全部使用注解,要么全部使用xml,个人建议注解,简单. 当实体类属性名称和数据库表属性名称一致时:无需配置Resul ...

  8. sqli-labs level 2

    来到第第二关 首先在后面添加一个 单引号看下报错信息 发现这里多多了一个引号  尝试去掉单引号看下回显结果   :    and 1=2 可以发现这里不需要添加单引号进行闭合,可以直接控制,所以接下来 ...

  9. 读《Adaptive Thresholding Using the Integral Image》自适应图像阈值

    图像的二值化问题总是一个问题.虽然使用深度学习的方法取得了不小的进展,但是传统的方法还是值得借鉴. 刚好随机游走到这篇文章 挖个07年的坟  地址:http://people.scs.carleton ...

  10. 编程题目: 找出最小的k个数

    找出最小或者最大的几个数我使用的是堆排序,效率为0(nlgn) 构建小顶堆返回末尾的k个数 或者 构建大顶堆返回前k个数 #!/usr/bin/env python3 def heap_sort(ar ...