Pagini recente » Cod sursa (job #663659) | Cod sursa (job #700733) | Cod sursa (job #741999) | Cod sursa (job #3226995) | Cod sursa (job #118322)
Cod sursa(job #118322)
#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, pair<long ,long> > V[2000101];
void print(long);
int main() {
fscanf(fopen("multiplu.in", "r"), "%ld %ld", &A, &B);
M = A*B / cmmdc(A,B);
Q.push( 1 ); V[1].first = true; V[1].second.first = -1, V[1].second.second=1;
while ( !Q.empty() ) {
long x;
x = Q.front(); Q.pop();
if ( !V[(x*10) % M].first ) {
Q.push((x*10)%M);
V[(x*10)%M].first = true;
V[(x*10)%M].second.first = x;
V[(x*10)%M].second.second= 0;
}
if ( !V[(x*10+1) % M].first ) {
Q.push((x*10+1)%M);
V[(x*10+1)%M].first = true;
V[(x*10+1)%M].second.first = x;
V[(x*10+1)%M].second.second= 1;
}
if ( V[0].first )
break;
}
freopen("multiplu.out","w", stdout);
print(0);
fclose(stdout);
return 0;
}
void print(long x) {
if ( x==-1 )
return;
print(V[x].second.first);
printf("%ld", V[x].second.second);
}