文章
49
粉丝
90
获赞
9
访问
29.4k
#include<algorithm>
#include<iostream>
#include<vector>
using namespace std;
void unique(vector<int>& v)
{
for (auto i = v.begin(); i < v.end() - 1; )
{
if (*i == *(i + 1))
{
i = v.erase(i);
}
else
{
i++;
}
}
for (auto t : v)
{
cout << t << " ";
}
}
int gcd(int a, int b)
{
if (b == 0)
{
return a;
}
return gcd(b, a % b);
}
int main()
{
int n;
auto sum = 599 * 600 / 2;
while (cin >> n)
{
vector<int> v(n);
for (int i = 0; i < n; i++)
{
int t;
cin >> t;
v[i] = t;
}
sort(v.begin(), v.end());
cout << endl;
//unique(v);
cout << endl;
sum = 0;
for (auto i = v.begin(); i < v.end(); i++)
for (auto j = i + 1; j < v.end(); j++)
{
if (gcd(*i, *j) == 1)
sum++;
}
cout << sum << endl;
}
return 0;
}
登录后发布评论
暂无评论,来抢沙发