Cod sursa(job #42853)

Utilizator gabitzish1Gabriel Bitis gabitzish1 Data 29 martie 2007 16:13:36
Problema Fractii Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.44 kb
#include<fstream.h>

long n, s;

int prim(long x,long y)
{
  while (x!=y)
    {
      if (x>y) x=x-y;
	else y-=x;
    }
  if (x==1) return 1;
  return 0;
}

void calcul()
{
  long i, j;
  ifstream in("fractii.in");
  in>>n;
  for (i=1; i<n; i++)
    for (j=i+1; j<=n; j++)
      if (prim(i,j)) s+=2;
  ofstream out("fractii.out");
  out<<s+1;
  in.close();
  out.close();
}

int main()
{
  calcul();
  return 0;
}