Pagini recente » Cod sursa (job #2086057) | Cod sursa (job #2934673) | Cod sursa (job #2201065) | Cod sursa (job #2042084) | Cod sursa (job #2260706)
#include <fstream>
#define DIM 100002
#define DIMC 1000002
using namespace std;
ifstream in ("pairs.in");
ofstream out("pairs.out");
int n, maxim = -1;
int ciur[DIMC];
bool viz[DIMC];
long long notPrime;
void CalcCiur(){
ciur[2] = 1;
for(int i = 2; i * i < DIMC; ++ i){
if(!ciur[i]){
for(int j = i; j < DIMC; j += i){
++ ciur[j];
}
}
}
for(int i = 2; i * i < DIMC; ++ i){
for(int j = i * i; j < DIMC; j += i * i)
ciur[j] = 0;
}
}
int main()
{
in>>n;
int x = 0;
for(int i = 1; i <= n; ++ i){
in>>x;
viz[x] = 1;
maxim = max(x, maxim);
}
CalcCiur();
long long nr = 0;
for(int i = 1; i < DIMC; ++ i){
if(ciur[i]){
for(int j = i; j < DIMC; j += i)
nr += viz[j];
if(ciur[i] % 2){
notPrime += 1LL * nr * (nr - 1) / 2LL;
}
else{
notPrime -= 1LL * nr * (nr - 1) / 2LL;
}
}
nr = 0;
}
out<<1LL * n * (n - 1) / 2LL - notPrime;
return 0;
}