链接:
https://codeforces.com/contest/1209/problem/A
题意:
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).
思路:
暴力枚举.
代码:
#include <bits/stdc++.h>
using namespace std;
int a[110];
int vis[110];
int main()
{
int n;
cin >> n;
for (int i = 1;i <= n;i++)
cin >> a[i];
sort(a+1, a+1+n);
int col = 0;
for (int i = 1;i <= n;i++)
{
if (vis[i] == 0)
{
col++;
for (int j = i;j <= n;j++)
{
if (a[j]%a[i] == 0)
vis[j] = 1;
}
}
}
cout << col << endl;
return 0;
}