Pagini recente » Cod sursa (job #637270) | Cod sursa (job #2688324) | Cod sursa (job #1195837) | Cod sursa (job #1670078) | Cod sursa (job #3272520)
#include <fstream>
using namespace std;
ifstream in("pairs.in");
ofstream out("pairs.out");
int n, ans, scz;
int v[100005];
int frec[1000005];
int main()
{
in>>n;
for(int i = 1; i<=n; i++)
{
in>>v[i];
frec[v[i]]++;
}
ans = (n * (n - 1)) / 2;
for(int i = 2; i<=1000000; i++)
{
int x = i;
int cnt = 0;
int ok = 1;
for(int d = 2; d*d<=x; d++)
{
if(x % d == 0)
{
cnt++;
int put = 0;
while(x % d == 0)
{
x /= d;
put++;
}
if(put > 1)
{
ok = 0;
break;
}
}
}
if(x > 1)
{
cnt++;
}
if(ok == 0)
{
continue;
}
int nr = 0;
for(int j = 1; i * j <= 1000000; j++)
{
nr += frec[i * j];
}
if(cnt % 2 == 1)
{
scz += nr;
}
else
{
scz -= nr;
}
}
ans -= scz;
out<<ans;
return 0;
}