Pagini recente » Cod sursa (job #1269421) | Cod sursa (job #482321) | Cod sursa (job #2290487) | Cod sursa (job #2685726) | Cod sursa (job #1777214)
#include <cstdio>
#include <cstring>
using namespace std;
const int maxDigits=1000000;
class HugeN{
private:
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(){
x[0]=0;
}
HugeN::HugeN(long long k){
x[0]=0;
do{
x[(int)++x[0]]=k%10;
k/=10;
} while (k);
}
void HugeN::read(){
x[0]=0;
char c;
while (scanf("%c",&c)!=EOF && c!='\n'){
c=c-'0';
x[(int)++x[0]]=c;
}
for (int i=1;i<=(x[0]>>1);i++){
int aux;
aux=x[i];
x[i]=x[x[0]-i+1];
x[x[0]-i+1]=aux;
}
}
void HugeN::print(){
for (int i=x[0];i>=1;i--){
printf("%d",x[i]);
}
}
long long HugeN::operator % (long long k){
long long r=0;
for (int i=x[0];i>=1;i--){
r=(r*10+x[i])%k;
}
return r;
}
HugeN HugeN::operator + (HugeN &other){
HugeN temp;
temp.x[0]=(x[0] > other.x[0] ? x[0] : other.x[0]);
int tr=0;
for (int i=1;i<=temp.x[0];i++){
tr=x[i]+other.x[i]+tr;
temp.x[i]=tr%10;
tr=tr/10;
}
if (tr){
temp.x[(int)++temp.x[0]]=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;
}