Cod sursa(job #1244538)

Utilizator BanhidiBanhidi Zoltan Banhidi Data 17 octombrie 2014 18:39:01
Problema Fractii Scor 0
Compilator c Status done
Runda Arhiva de probleme Marime 0.57 kb
#include <stdio.h>

int lnko(int x, int y) {
   while (x!=y)
      if (x>y) x-=y;
         else y-=x;
   return x;
}

int main() {
   struct tort {
      int sz,n;
   }t[1000];
   int n,m=0,i,j,k,u,b;
   FILE *f;
   f=fopen("fractii.in","r");
   fscanf(f,"%d",&n);
   fclose(f);
   for (i=1; i<=n; i++)
      for (j=1; j<=n; j++) {
         k=lnko(i,j); b=0;
         for (u=0; u<m; u++)
            if ((t[u].sz==i/k) && (t[u].n==j/k)) b=1;
         if (b==0) { t[m].sz=i/k; t[m].n=j/k; ++m; }
      }
   f=fopen("fractii.out","w");
   fprintf(f,"%d",m);
   fclose(f);
   return 0;
}