Cod sursa(job #109263)

Utilizator andytrAlexandru Traista andytr Data 25 noiembrie 2007 09:48:50
Problema Pairs Scor 20
Compilator cpp Status done
Runda preONI 2008, Runda 1, Clasele 11-12 Marime 0.61 kb
#include <stdio.h>

int n;
long a[10000];

void cit()
{
 FILE *f=fopen("pairs.in","r");
 int i;
 fscanf(f,"%d",&n);
 for(i=1;i<=n;i++)
  fscanf(f,"%ld",&a[i]);
 fclose(f);
}

void scr(int x)
{
 FILE *f=fopen("pairs.out","w");
 fprintf(f,"%d",x);
 fclose(f);
}

int prime(long a,long b)
{
 long r;
 if(!b)
  return 0;
 r=a%b;
 while(r)
  {
   a=b;
   b=r;
   r=a%b;
  }
 if(b!=1)
  return 0;
 return 1;
}

int sol()
{
 int i,j,x=0;
 for(i=1;i<n;i++)
  for(j=i+1;j<=n;j++)
   if(prime(a[i],a[j]))
    x++;
 return x;
}

int main()
{
 cit();
 scr(sol());
 return 0;
}