Cod sursa(job #392170)

Utilizator Alexa_ioana_14Antoche Ioana Alexandra Alexa_ioana_14 Data 6 februarie 2010 21:56:27
Problema Multiplu Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.7 kb
#include<cstdio>
using namespace std;
#include<queue>
int a,b,c;
int cmmdc()
{
	int r;
	while (!b)
	{
		r=a%b;
		a=b;
		b=r;
	}
	return a;
}
queue<int>q;
void bf()
{
	q.push(1);
	int x,y;
	while (true)
	{
		x=q.front();
		q.pop();
		y=x*10%c;
		++b;
		if (!y)
			return;
		q.push(y);
		y=(x*10+1)%c;
		++b;
		if (!y)
			return;
		q.push(y);
	}
}
void afis(int b)
{
	if (!b)
		return;
	if (b&1)
	{
		afis(b>>1);
		printf("0");
	}
	else
	{
		afis((b-1)>>1);
		printf("1");
	}
}
int main()
{
	freopen("multiplu.in","r",stdin);
	freopen("multiplu.out","w",stdout);
	scanf("%d%d",&a,&b);
	int p=a*b;
	c=p/cmmdc();
	bf();
	printf("1");
	afis(b);
	return 0;
}