Pagini recente » Cod sursa (job #779751) | Cod sursa (job #2375925) | Cod sursa (job #2272054) | Cod sursa (job #40390) | Cod sursa (job #1777283)
#include <cstdio>
#include <cstring>
const int nmax=1000000;
using namespace std;
class Hugen
{
private:
int x0;
char x[nmax+5];
public:
Hugen()
{
x0=0;
}
Hugen(long long nr)
{
x0=0;
do
{
x[++x0]=nr%10;
nr/=10;
}while(nr);
}
void print()
{
int i;
for(i=x0;i>=1;i--)
printf("%d", x[i]);
printf("\n");
}
Hugen operator+=(Hugen &other);
long long operator%(long long k);
void read();
};
void Hugen::read()
{
x0=0;
char c;
while (scanf("%c",&c)!=EOF && c!='\n'){
c=c-'0';
x[(int)++x0]=c;
}
for (int i=1;i<=(x0>>1);i++){
char aux;
aux=x[i];
x[i]=x[x0-i+1];
x[x0-i+1]=aux;
}
}
Hugen Hugen::operator += (Hugen &other){
x0=(x0 > other.x0 ? x0 : other.x0);
int tr=0;
for (int i=1;i<=x0;i++){
tr=x[i]+other.x[i]+tr;
x[i]=tr%10;
tr=tr/10;
}
if (tr){
x[(int)++x0]=tr;
}
return *this;
}
long long Hugen::operator%(long long k)
{
int i;
long long r=0;
for(i=x0;i>=1;i--)
r=(r*10+x[i])%k;
return r;
}
char s[nmax+1];
int main()
{
freopen("next.in", "r", stdin);
freopen("next.out", "w", stdout);
long long d, r;
Hugen n;
n.read();
scanf("%lld",&d);
r=n%d;
if (r==0){
r=d;
}
r=d-r;
Hugen ot(r);
n+=ot;
n.print();
return 0;
}