Cod sursa(job #115422)

Utilizator robbyRobertino robert robby Data 16 decembrie 2007 12:37:03
Problema Multiplu Scor 10
Compilator cpp Status done
Runda preONI 2008, Runda 2, Clasa a 10-a Marime 0.6 kb
#include <stdio.h>
long long euclid(long long x,long long y)
{
	long r;
	if (x<y)
		{
			r=x;
			x=y;
			y=r;
		}
	do
	{
		r=x%y;
		x=y;
		y=r;
	}
	while (r);
	return x;
}

int ok(long long x)
{
	int k=1;
	while (x>0)
		{
			if ((x%10!=1)&&(x%10!=0))
				{k=0;break;}
			x/=10;
		}
	return k;
}
FILE *f,*g;
int main()
{
	long long a,b,i;
	long long c;
	f=fopen("multiplu.in","rt");
	g=fopen("multiplu.out","wt");
	fscanf(f,"%lld %lld",&a,&b);
	c=a*b/euclid(a,b);
	for (i=1;;i++)
		if (ok(c*i))
			break;
	fprintf(g,"%lld\n",c*i);
	fclose(f);
	fclose(g);
	return 0;
}