Pagini recente » Profil florinhaja | Cod sursa (job #2029213) | Cod sursa (job #405645) | Cod sursa (job #839952) | Cod sursa (job #1284600)
#include <cstdio>
#include <cstring>
#include <cctype>
#define IN "next.in"
#define OUT "next.out"
#define MAX 1000005
using namespace std;
class HUGE
{
private:
int x[MAX];
public:
HUGE()
{
memset(x, 0, sizeof(x));
*x = 1;
}
void operator =(const char s[])
{
memset(x, 0, sizeof(x));
int i = strlen(s) - 2;
do
{
x[++*x] = s[i] - '0';
--i;
}
while(i >= 0);
}
void operator +=(int a)
{
int i = 1, t = 0;
do
{
t = t + x[i] + a % 10;
x[i] = t % 10;
t /= 10;
a /= 10;
++i;
}
while(a);
while(t)
{
if(i > x[0])
++x[0];
t = t + x[i];
x[i] = t % 10;
t /= 10;
++i;
}
}
long long operator %(const long long &MOD)
{
long long r = 0;
int i;
for(i = *x; i; --i)
r = ((r << 1) + (r << 3) + x[i]) % MOD;
return r;
}
void print(FILE *out = stdout)
{
for(int i = *x; i; --i)
fprintf(out, "%d", x[i]);
}
};
FILE *in, *out;
HUGE M;
char aux[MAX];
long long d, l;
void citire()
{
in = fopen(IN, "r");
fgets(aux, MAX, in);
M = aux;
fscanf(in, "%lld", &d);
fclose(in);
}
void rezolvare()
{
l = M % d;
if(l)
M += (d - l);
}
void afisare()
{
out = fopen(OUT, "w");
M.print(out);
fputc('\n', out);
fclose(out);
}
int main()
{
citire();
rezolvare();
afisare();
return 0;
}