Pagini recente » Cod sursa (job #2861431) | Cod sursa (job #734467) | Cod sursa (job #1749949) | Cod sursa (job #2709953) | Cod sursa (job #1236732)
#include <cstdio>
#include <cstring>
using namespace std;
#define MAX_DIGITS (1000005)
#define max(x,y) (x > y ? x : y)
class HugeN {
private:
int x[MAX_DIGITS];
public:
HugeN() {
memset(x, 0, sizeof(x));
x[0] = 1;
}
HugeN(int n) {
memset(x, 0, sizeof(x));
x[0] = 0;
do {
x[++x[0]] = n % 10;
n = n / 10;
} while(n);
}
HugeN(const HugeN &other) {
memcpy(x, other.x, sizeof(other.x));
}
void print() {
for(int i = x[0]; i >= 1; i--)
printf("%d", x[i]);
printf("\n");
}
HugeN operator+(HugeN other) {
long i, t;
HugeN r(0);
r.x[0] = x[0] > other.x[0] ? x[0] : other.x[0];
for(t = 0, i = 1; i <= r.x[0]; i++) {
t = x[i] + other.x[i] + t;
r.x[i] = t % 10;
t /= 10;
}
if(t)
r.x[0]++, r.x[r.x[0]] = t;
}
HugeN operator+=(const HugeN &other) {
int i, t;
x[0] = max(x[0], other.x[0]);
for(t = 0, i = 1; i <= x[0]; i++) {
t = x[i] + other.x[i] + t;
x[i] = t % 10;
t /= 10;
}
if(t)
x[0]++, x[x[0]] = t;
}
HugeN & operator+=(const long long &other) {
long long t;
int i;
t = other;
for(i = 1; i <= x[0]; i++) {
t = x[i] + t;
x[i] = t % 10;
t /= 10;
}
while(t) {
x[0]++;
x[x[0]] = t % 10;
}
return *this;
}
long long operator%(long long other) {
long long r = 0;
int i;
for(i = x[0]; i > 0; i--) {
r = r * 10 + x[i];
r %= other;
}
return r ;
}
void read() {
char *s;
s = new char[MAX_DIGITS + 1];
gets(s);
long i;
i = strlen(s);
x[0] = i;
while(i > 0) {
x[x[0] - i + 1] = s[i - 1] - '0';
i--;
}
}
};
HugeN N;
long long D;
int main() {
int i, j;
freopen("next.in", "r", stdin);
freopen("next.out", "w", stdout);
N.read();
scanf("%lld", &D);
long long t;
t = (D - N % D);
if(t != D)
N += t;
N.print();
return 0;
}