Cod sursa(job #1486247)

Utilizator justsomedudePalade Thomas-Emanuel justsomedude Data 14 septembrie 2015 14:16:12
Problema Multiplu Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.02 kb
#include<fstream>
#include<queue>
#include<cstdlib>
#include<iostream>
using namespace std;

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

queue <int> q;
int A,AA,B,BB,M,aux;
int CMMDC,CMMMC;

int cmmdc(long long int A, long long int B)
{
   int R;
   while (B!=0)
  {
    R=A%B;
    A=B;
    B=R;
  }
  return A;
}

void Citire()
{
  fin >> A >> B;
  AA=A; BB=B;
  CMMDC = cmmdc(A,B);
  A=AA; B=BB;
  CMMMC = (A*B)/CMMDC;
}


void Rezolva()
{
  int  x,y;
  /// M = CMMMC
  q.push(1);

  while (!q.empty())
  {
      x = q.front();
      q.pop();
      y = x * 10;


      if (y%CMMMC == 0)
      {
          fout << y << "\n";
          exit(0);
      }

      else
      {
          q.push(y);
      }

      y++;

      if (y%CMMMC == 0)
      {
          fout << y << "\n";
          exit(0);
      }

      else
      {
          q.push(y);
      }
  }
}


int main ()
{
  Citire();
  Rezolva();
  fin.close();
  fout.close();
  return 0;
}