Cod sursa(job #115474)

Utilizator lamez0rBogdan Bondor lamez0r Data 16 decembrie 2007 12:48:48
Problema Multiplu Scor 10
Compilator c Status done
Runda preONI 2008, Runda 2, Clasele 11-12 Marime 0.65 kb
#include <stdio.h>

int euclid (long int x, long int y)
    {
    long int d,i,r;
    d=x;
    i=y;
    while (i!=0)
	  {
	  r=d%i;
	  d=i;
	  i=r;
	  }
    return d;
    }

int main ()
 {
 long int o,y,a,b,x;
 int gasit=0,c,i,ok;
 FILE *f;
 f=fopen("multiplu.in","r");
 fscanf(f,"%ld%ld",&a,&b);
 fclose(f);
 x=(a*b)/euclid(a,b);
 o=x;
 i=1;
 while (!gasit)
       {
       y=o*i++;
       x=y;
       ok=1;
       while (x!=0&&ok)
	     {
	     c=x%10;
	     if (c!=0&&c!=1)
		ok=0;
	     x=x/10;
	     }
       if (ok)
	  gasit=1;
       }
 f=fopen("multiplu.out","w");
 fprintf(f,"%ld",y);
 fclose(f);
 return 0;
 }