Cod sursa(job #2330343)

Utilizator Asgari_ArminArmin Asgari Asgari_Armin Data 28 ianuarie 2019 11:34:59
Problema Multiplu Scor 30
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.78 kb
#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;
}