Cod sursa(job #1405312)

Utilizator StarGold2Emanuel Nrx StarGold2 Data 29 martie 2015 00:33:40
Problema Multiplu Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.06 kb
#include <fstream>
#define DIM 2000010
using namespace std;

ifstream fin ("multiplu.in" );
ofstream fout("multiplu.out");

int N, M, i, j, K, ok, minim;
int C[DIM], a, b, r, X, Y, Z;
int F[DIM], p, u;

int CMMDC(int a, int b){
     int c;
     while(b != 0){
          c = a % b;
          a = b;
          b = c;
     }
     return a;
}

void SetUp(){
     fin >> X >> Y;
     Z = X * Y / CMMDC(X, Y);
     return;
}

void CodeExpert(){
     p = 1; u = 1;
     C[1] = 1;
     while(1 == 1){
          X = C[p];
          Y = C[p] * 10 + 0;
          if(F[Y%Z] == 0){
               u ++;
               C[u] = Y;
               F[Y%Z] = 1;
               if(Y % Z == 0)
                    break;
          }
          Y = C[p] * 10 + 1;
          if(F[Y%Z] == 0){
               u ++;
               C[u] = Y;
               F[Y%Z] = 1;
               if(Y % Z == 0)
                    break;
          }
          p ++;
     }
     fout << C[u];
     return;
}

int main(){
     SetUp();
     CodeExpert();
     return 0;
}