Pagini recente » Cod sursa (job #1548643) | Cod sursa (job #2401438) | Cod sursa (job #1293911) | Cod sursa (job #1853274) | Cod sursa (job #1777254)
#include <cstdio>
#include <cstring>
using namespace std;
const int maxDigits=1000000;
class HugeN{
private:
int x0;
char x[maxDigits];
public:
HugeN();
HugeN(long long k);
void read();
void print();
long long operator % (long long k);
HugeN operator + (HugeN &other);
};
HugeN::HugeN(){
x0=0;
}
HugeN::HugeN(long long k){
x0=0;
do{
x[(int)++x0]=k%10;
k/=10;
} while (k);
}
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;
}
}
void HugeN::print(){
for (int i=x0;i>=1;i--){
printf("%d",(int)x[i]);
}
}
long long HugeN::operator % (long long k){
long long r=0;
for (int i=x0;i>=1;i--){
r=(r*10+x[i])%k;
}
return r;
}
HugeN HugeN::operator + (HugeN &other){
HugeN temp;
temp.x0=(x0 > other.x0 ? x0 : other.x0);
int tr=0;
for (int i=1;i<=temp.x0;i++){
tr=x[i]+other.x[i]+tr;
temp.x[i]=tr%10;
tr=tr/10;
}
if (tr){
temp.x[(int)++temp.x0]=tr;
}
return temp;
}
int main(){
freopen("next.in","r",stdin);
freopen("next.out","w",stdout);
long long k,r;
HugeN n,t;
n.read();
scanf("%lld",&k);
r=n%k;
if (r==0){
r=k;
}
r=k-r;
HugeN ot(r);
t=n+ot;
t.print();
return 0;
}