Cod sursa(job #498137)

Utilizator crushackPopescu Silviu crushack Data 4 noiembrie 2010 11:26:47
Problema Pairs Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.53 kb
#include <stdio.h>

const char IN[]="pairs.in",OUT[]="pairs.out";

int N;
int a[1000000];

int primes(int x,int c)
{
	int d=2;
	while ( d*d<=x )
	{
		if (x%d==0)
		{
			c-=a[d];
			a[d]++;
			while (x%d==0)
				x/=d;
		}
		d++;
	}
	if (x!=1)
		c-=a[x],
		a[x]++;
	return c;
}

int main()
{
	int i,x,R;
	freopen(IN,"r",stdin);
	scanf("%d",&N);
	R=0;
	for (i=0;i<N;i++)
	{
		scanf("%d",&x);
		R+= primes(x,i);
	}
	fclose(stdin);
	
	freopen(OUT,"w",stdout);
	printf("%d",R);
	fclose(stdout);
	return 0;
}