Pagini recente » Cod sursa (job #580740) | Cod sursa (job #2246074) | Cod sursa (job #1057485) | Cod sursa (job #706961) | Cod sursa (job #115812)
Cod sursa(job #115812)
#include <stdio.h>
#include <vector>
#define NMax 2000005
long A, B;
FILE *f, *g;
int C[NMax], rest[NMax], x;
int up[NMax], cif[NMax];
int solx[NMax];
int in, sf;
void citire();
void rez();
long cmmdc( long A, long B );
int main()
{
citire();
rez();
return 0;
}
void rez()
{
int i, n;
long M = A*B /cmmdc( A, B ), poz, pozb;
//* */std::vector<int> sol;
C[0] = 1;
rest[1%M] = 1;
while ( 1 )
{
poz = in;
x = C[in++];
rest[(x%M)] = 0;
if ( x%M == 0 )
{
pozb = in-1;
break;
}
if ( rest[(x*10)%M] == 0 )
{
C[++sf] = (x*10)%M;
rest[(x*10)%M] = 1;
cif[sf] = 0;
up[sf] = poz;
if ( C[sf] == 0 )
{
pozb = sf;
break;
}
}
if ( rest[(x*10+1)%M] == 0)
{
C[++sf] = (x*10+1)%M;
rest[(x*10+1)%M] = 1;
cif[sf] = 1;
up[sf] = poz;
if ( C[sf] == 0 )
{
pozb = sf;
break;
}
}
}
n=0;
//sol.push_back( cif[pozb] );
solx[n] = cif[pozb];
while ( up[pozb] )
{
n++;
solx[n] = cif[up[pozb]];
//sol.push_back( cif[up[pozb]] );
up[pozb] = up[up[pozb]];
}
n++;
solx[n] = 1;
n++;
//sol.push_back( 1 );
for (i=n-1; i>=0; i--)
fprintf( g, "%d", solx[i] );
fprintf( g, "\n" );
}
long cmmdc( long A, long B )
{
long R;
while ( B )
{
R = A % B;
A = B;
B = R;
}
return A;
}
void citire()
{
f = fopen( "multiplu.in", "rt" );
g = fopen( "multiplu.out", "wt" );
fscanf( f, "%ld %ld", &A, &B );
fclose( f );
}