Pagini recente » Cod sursa (job #2278871) | Cod sursa (job #344842) | Cod sursa (job #1121675) | Cod sursa (job #1333812) | Cod sursa (job #118318)
Cod sursa(job #118318)
#include <cstdio>
#include <string>
#include <queue>
#include <utility>
using namespace std;
long A,B,M;
long cmmdc(long a, long b) {
if ( a<b ) { long r = a; a = b; b = r; }
while ( b ) { long r = a%b; a=b; b=r; }
return a;
}
queue < long > Q;
pair<bool, string> V[20000101];
int main() {
fscanf(fopen("multiplu.in", "r"), "%ld %ld", &A, &B);
return 0;
M = A*B / cmmdc(A,B);
Q.push( 1 ); V[1].first = true; V[1].second = "1";
while ( !Q.empty() ) {
pair <string, long> x;
x.second = Q.front(); Q.pop();
x.first = V[x.second].second;
if ( !V[(x.second*10) % M].first ) {
Q.push((x.second*10)%M);
V[(x.second*10)%M].first = true;
V[(x.second*10)%M].second = x.first+"0";
}
if ( !V[(x.second*10+1) % M].first ) {
Q.push((x.second*10)%M);
V[(x.second*10+1)%M].first = true;
V[(x.second*10+1)%M].second = x.first+"1";
}
if ( V[0].first )
break;
}
fprintf(fopen("multiplu.out", "w"), "%s", V[0].second.c_str());
return 0;
}