Pagini recente » Cod sursa (job #2511882) | Cod sursa (job #2263878) | Cod sursa (job #3257812) | Cod sursa (job #3161335) | Cod sursa (job #2330343)
#include <fstream>
using namespace std;
ifstream cin( "multiplu.in" );
ofstream cout( "multiplu.out" );
int v[20];
int n, a, b, ok = 0;
unsigned long long nr, cnr;
void afis( int poz ){
for( int i = 0; i < poz; ++i )
cout << v[i] << " ";
cout << "\n";
}
void bkt( int poz ){
if( poz == n ){
ok = nr = 0;
for( int k = poz - 1; k >= 0; --k )
nr = nr * 10 + v[k];
if( nr % a == 0 && nr % b == 0 && nr > 0 )
cnr = min( cnr, nr );
}
else{
for( int i = 0; i < 2; ++i ){
for( int j = 1; j <= n; ++j )
v[poz] = i;
bkt( poz + 1 );
}
}
}
int main()
{
n = 20;
cnr = (unsigned long long)1 << 63;
cnr--;
cnr *= 2;
cin >> a >> b;
bkt(0);
cout << cnr;
return 0;
}