Pagini recente » Cod sursa (job #1674990) | Cod sursa (job #3134299) | Cod sursa (job #2671242) | Cod sursa (job #879890) | Cod sursa (job #1747557)
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
using namespace std;
#define NMAX 1000005
char s[NMAX-5];
class HugeN
{
private: int x[NMAX];
public: HugeN();
HugeN(const char *s){
int l=strlen(s);
memset(x,0,sizeof(x));
x[0]=0;
for(l--;l>=0;l--)
x[++x[0]]=s[l]-'0';
}
void get_huge();
HugeN&operator*(const int k){
HugeN temp;
int tr,i,aux;
tr=0;
temp.x[0]=x[0];
for(i=1;i<=temp.x[0];i++)
temp.x[i]=x[i]*k;
for(i=1;i<=temp.x[0];i++){
aux=temp.x[i]+tr;
temp.x[i]=aux%10;
tr=aux/10;
}
while(tr){
aux=temp.x[0];
aux++;
temp.x[aux]=tr%10;tr/=10;
temp.x[0]=aux;
}
return temp;
};
HugeN &operator +(long long k){
long long trn,aux;
trn=k;
for(int i=1;i<=x[0];i++){
aux=x[i]+trn;
x[i]=aux%10;
trn=aux/10;
}
while(trn){
x[++x[0]]=trn % 10;
trn/=10;
}
return *this;
};
int cmp(const HugeN&other);
long long operator%( int k){
long long r=0;
for(int i=x[0];i>=1;--i){
r=r*10+x[i];
r=r%k;
};
return r;
};
};
void HugeN::get_huge()
{
int i;
for (i=x[0];i>=1;i--)
printf("%d", x[i]);
printf ("\n");
}
int HugeN::cmp(const HugeN&other)
{
if (x[0]<other.x[0])
return -1;
else
if(x[0]>other.x[0])
return 1;
else
{
for (int i=x[0];i>=1;i--) {
if (x[i]>other.x[i])
return 1;
else if (x[i]<other.x[i])
return -1;
}
}
return 0;
}
int main()
{
freopen("next.in","r",stdin);
freopen("next.out","w",stdout);
scanf("%s",s);
HugeN r(s);
long long d,j;
scanf("%lld",&d);
j=r%d;
if(j==0)
r.get_huge();
else{
r=r+(d-j);
r.get_huge();
}
return 0;
}