CF1209A.Paint the Numbers

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a sequence of integers a1,a2,…,ana_1, a_2, \dots, a_n. 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][40, 10, 60] in a single color, because they are all divisible by 1010. 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]a=[6, 2, 3, 4, 12] then two colors are required: let's paint 66, 33 and 1212 in the first color (66, 33 and 1212 are divisible by 33) and paint 22 and 44 in the second color (22 and 44 are divisible by 22). For example, if a=[10,7,15]a=[10, 7, 15] then 33 colors are required (we can simply paint each element in an unique color).

给你一个整数序列 a1,a2,…,ana_1, a_2, \dots, a_n。你需要为这些元素涂上颜色,使得:

  • 对于任意一种颜色,该颜色下所有元素都必须能被该颜色中最小的元素整除;
  • 所使用的颜色种类数最少。

例如,将元素 [40,10,60][40, 10, 60] 全部涂成同一种颜色是可行的,因为它们都能被 1010 整除。你可以任意多次使用同一种颜色(特别地,允许某种颜色仅用于一个元素)。同一颜色的元素无需在原序列中连续。

例如,若 a=[6,2,3,4,12]a=[6, 2, 3, 4, 12],则需要两种颜色:将 66、33 和 1212 涂成第一种颜色(它们均能被 33 整除),将 22 和 44 涂成第二种颜色(它们均能被 22 整除)。又如,若 a=[10,7,15]a=[10, 7, 15],则需要 33 种颜色(可简单地将每个元素分别涂成不同颜色)。

输入格式

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

The second line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤1001 \le a_i \le 100). These numbers can contain duplicates.

第一行包含一个整数 nn(1≤n≤1001 \le n \le 100),表示给定序列的长度。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤1001 \le a_i \le 100)。这些数字可能包含重复元素。

输出格式

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

输出以合法方式为所有给定数字着色所需的最少颜色数。

输入输出样例

  • 输入#1

    6
    10 2 3 5 4 2

    输出#1

    3
  • 输入#2

    4
    100 100 100 100

    输出#2

    1
  • 输入#3

    8
    7 6 5 4 3 2 2 3

    输出#3

    4

说明/提示

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

  • paint in the first color the elements: a1=10a_1=10 and a4=5a_4=5,
  • paint in the second color the element a3=3a_3=3,
  • paint in the third color the elements: a2=2a_2=2, a5=4a_5=4 and a6=2a_6=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 44 colors is:

  • paint in the first color the elements: a4=4a_4=4, a6=2a_6=2 and a7=2a_7=2,
  • paint in the second color the elements: a2=6a_2=6, a5=3a_5=3 and a8=3a_8=3,
  • paint in the third color the element a3=5a_3=5,
  • paint in the fourth color the element a1=7a_1=7.

在第一个例子中,一种将元素用 33 种颜色染色的可行方案是:

  • 用第一种颜色染色的元素:a1=10a_1=10 和 a4=5a_4=5,
  • 用第二种颜色染色的元素:a3=3a_3=3,
  • 用第三种颜色染色的元素:a2=2a_2=2、a5=4a_5=4 和 a6=2a_6=2。

在第二个例子中,可以仅使用一种颜色对所有元素进行染色。

在第三个例子中,一种将元素用 44 种颜色染色的可行方案是:

  • 用第一种颜色染色的元素:a4=4a_4=4、a6=2a_6=2 和 a7=2a_7=2,
  • 用第二种颜色染色的元素:a2=6a_2=6、a5=3a_5=3 和 a8=3a_8=3,
  • 用第三种颜色染色的元素:a3=5a_3=5,
  • 用第四种颜色染色的元素:a1=7a_1=7。

输入解题思路,AI测评打分。不知道怎么写?

首页