Cod sursa(job #115438)

Utilizator VmanDuta Vlad Vman Data 16 decembrie 2007 12:41:06
Problema Multiplu Scor 0
Compilator cpp Status done
Runda preONI 2008, Runda 2, Clasa a 10-a Marime 0.95 kb
using namespace std;
#include <stdio.h>
#include <vector>

#define Mmax 2000000

int A,B,D,M;
int h[Mmax];
int hh[Mmax];

void cmmdc(int A,int B)
{
 int r;
 while (B)
       {
        r=A%B;
        A=B;
        B=r;
       }
 D=A;
}

void teste_mari()
{
 int r,rr,i,j;
 h[1]=1;
 r=1;rr=0;
 i=1;
 while (1)
       {
        ++i;
        r=(r*10+1)%M;
        rr=((rr+1)*10)%M;
        if ((h[r]>0)||(hh[r]>0)||(r==0)) break;
        h[r]=i;
        hh[rr]=i;
       }
 if ((r==0)||(h[r]>0))
 {
 for (j=1;j<=i-h[r];++j)
     printf("%d",1);
 for (j=1;j<=h[r];++j)
     printf("%d",0);
 }
 else
 {
  for (j=1;j<=i-hh[r];++j)
      printf("%d",1);
  for (j=1;j<hh[r];++j)
      printf("%d",0);
  printf("%d",1);
 }
}

int main()
{
 freopen("multiplu.in","r",stdin);
 freopen("multiplu.out","w",stdout);
 scanf("%d %d",&A,&B);
 cmmdc(A,B);
 M=A*B/D;
 teste_mari();
 fclose(stdin);
 fclose(stdout);
 return 0;
}