Pagini recente » Cod sursa (job #186824) | Cod sursa (job #1723819) | Cod sursa (job #2438527) | Cod sursa (job #2964927) | Cod sursa (job #109246)
Cod sursa(job #109246)
#include <iostream>
#include <stdio.h>
using namespace std;
const int maxM = 1000001;
bool apM[ maxM ];
bool ciur[ maxM ];
int n;
int nec;
int vmax;
long long sol;
int aux;
int nr;
int i,j;
int main()
{
freopen("pairs.in","r",stdin);
freopen("pairs.out","w",stdout);
scanf("%d\n", &n );
for ( i = 1; i <= n; i++ ) {
scanf("%d\n", &aux );
if ( !apM[ aux ] ) nr++;
apM[ aux ] = 1;
if ( aux > vmax ) vmax = aux;
}
sol = ( long long ) ( nr*(nr-1) )/2;
for ( i = 2; i <= vmax; i++ ) {
if ( !ciur[ i ] ) {
nec = 0;
if ( apM[ i ] ) nec = 1;
for ( j = i+i; j <= vmax; j += i ) {
ciur[ j ] = 1;
if ( apM[ j ] ) {
sol -= nec;
nec++;
}
}
}
}
printf("%lld\n", sol );
fclose(stdin);
fclose(stdout);
return 0;
}