Cod sursa(job #109836)

Utilizator Binary_FireFlorin Pogocsan Binary_Fire Data 25 noiembrie 2007 12:48:03
Problema Pairs Scor 20
Compilator cpp Status done
Runda preONI 2008, Runda 1, Clasa a 10-a Marime 0.7 kb
#include <cstdio>
#include <vector>

using namespace std;

#define fin  "pairs.in"
#define fout "pairs.out"

#define pb push_back
#define sz(c) (int)((c).size())

const int Nmax = 100010;

int N,ret;
vector <int> v[Nmax];

int main()
{
	int a,i,j,k,l,bun;

	freopen(fin,"r",stdin);
	freopen(fout,"w",stdout);
	
	scanf("%d",&N);

	for (i=1;i<=N;++i)
	{
		scanf("%d",&a);
		for (j=2;j*j<=a && a>1;++j)
			if (a%j==0)
			{
				v[i].pb(j);
				while (a%j==0)
					a/=j;
			}
		if (a > 1) v[i].pb(a);
	}

	for (i=1;i<=N;++i)
	for (j=1;j<i;++j)
	{
		bun=1;
		for (l=0;l<sz(v[i]) && bun;++l)
		for (k=0;k<sz(v[j]) && bun;++k)
			if ( v[i][l] == v[j][k] )
				bun = 0;
		if ( bun ) ++ret;
	}

	printf("%d\n",ret);

	return 0;
}