Pagini recente » Cod sursa (job #2634867) | Cod sursa (job #1452441) | Cod sursa (job #3126353) | Cod sursa (job #951384) | Cod sursa (job #115831)
Cod sursa(job #115831)
#include <stdio.h>
#define NMax 2000005
long A, B;
FILE *f, *g;
int C[NMax], rest[NMax], x;
int up[NMax], cif[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, x1, x2;
long M = A*B /cmmdc( A, B ), poz, pozb;
C[0] = 1;
while ( !rest[0] )
{
poz = in;
x = C[in++];
rest[(x%M)] = 0;
x1 = (x*10)%M;
if ( rest[x1] == 0 )
{
C[++sf] = x1;
rest[x1] = sf;
cif[sf] = 0;
up[sf] = poz;
}
x2 = (x*10+1)%M;
if ( rest[x2] == 0)
{
C[++sf] = x2;
rest[x2] = sf;
cif[sf] = 1;
up[sf] = poz;
}
}
n=0;
pozb = rest[0];
rest[0] = cif[pozb];
n++;
while ( up[pozb] )
{
rest[n] = cif[up[pozb]];
up[pozb] = up[up[pozb]];
n++;
}
rest[n] = 1;
n++;
for (i=n-1; i>=0; i--)
fprintf( g, "%d", rest[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 );
}