Pagini recente » Cod sursa (job #3003747) | Cod sursa (job #2614601) | Cod sursa (job #2939319) | Cod sursa (job #2349065) | Cod sursa (job #115102)
Cod sursa(job #115102)
#include <cstdio>
#include <string>
using namespace std;
#define MAX 2000000
inline long cmmdc(long a, long b) {
while ( b ) { long r = a%b; a = b; b = r; }
return a;
}
long a,b,c;
long R[MAX]; // R[i] = x => restul i se obtine din 1111..1 de x ori
string m;
int main() {
fscanf(fopen("multiplu.in", "r"), "%ld %ld", &a, &b);
c = a*b / cmmdc(a,b);
long r,x;
for (r=1, x=1; r!=0 && R[r]==0; r=(r*10+1)%c, ++x)
R[r] = x;
if ( !r ) {
R[0] = x;
while ( x-- ) m += "1";
} else {
m = "1";
while ( (--x)>R[r] ) m+="1";
while ( x-- ) m+="0";
}
fprintf(fopen("multiplu.out","w"), "%s\n", m.c_str());
return 0;
}