Cod sursa(job #115102)

Utilizator sima_cotizoSima Cotizo sima_cotizo Data 16 decembrie 2007 10:50:51
Problema Multiplu Scor 0
Compilator cpp Status done
Runda preONI 2008, Runda 2, Clasa a 10-a Marime 0.62 kb
#include <cstdio>
#include <string>
using namespace std;

#define MAX 2000000

inline long cmmdc(long a, long b) {
	while ( b ) { long r = a%b; a = b; b = r; }
	return a;
}

long a,b,c;
long R[MAX];	// R[i] = x => restul i se obtine din 1111..1 de x ori
string m;


int main() {
	fscanf(fopen("multiplu.in", "r"), "%ld %ld", &a, &b);

	c = a*b / cmmdc(a,b);

	long r,x;
	for (r=1, x=1; r!=0 && R[r]==0; r=(r*10+1)%c, ++x)
    	R[r] = x;
	if ( !r ) {
		R[0] = x;
		while ( x-- ) m += "1";
	} else {
		m = "1";
		while ( (--x)>R[r] ) m+="1";
		while ( x-- ) m+="0";
	}


	fprintf(fopen("multiplu.out","w"), "%s\n", m.c_str());
	return 0;
}