Pagini recente » Cod sursa (job #2801945) | Cod sursa (job #1523765) | Cod sursa (job #763886) | Cod sursa (job #855197) | Cod sursa (job #1777269)
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
const int MAX_DIGITS=1000000;
const int BASE=10;
const int MAX_INT=(1LL << 31)-1;
char s[MAX_DIGITS+5];
class HugeN
{
private: long long x[MAX_DIGITS+5];
public:
HugeN()
{
memset(x,0,sizeof(x));
x[0]=1;
}
HugeN(long long nr)
{
memset(x,0,sizeof(x));
do
{
x[++x[0]]=nr%BASE;
nr/=BASE;
}while(nr);
}
HugeN(HugeN &other)
{
memset(x,0,sizeof(x));
memcpy(x,other.x,sizeof(other.x));
}
HugeN(char *s)
{
x[0]=strlen(s);
for(int i=1;i<=x[0];i++)
x[i]=s[x[0]-i]-'0';
}
void print()
{
for(int i=x[0];i>=1;i--)
printf("%d",x[i]);
printf("\n");
}
int cmp(const HugeN &other);
HugeN operator +(const HugeN &other);
HugeN operator +(long long k);
HugeN operator -(const HugeN &other);
HugeN operator -(int k);
HugeN operator *(int k);
HugeN operator *(const HugeN &other);
HugeN operator /(int k);
HugeN operator /(const HugeN &other);
long long operator %(long long k);
HugeN operator %(const HugeN &other);
HugeN operator ^(int k);
HugeN operator +=(const HugeN &other);
HugeN operator -=(const HugeN &other);
HugeN operator *=(int k);
HugeN operator *=(const HugeN &other);
HugeN operator /=(int k);
bool operator >(const HugeN &other);
bool operator >=(const HugeN &other);
bool operator <(const HugeN &other);
bool operator <=(const HugeN &other);
bool operator ==(const HugeN &other);
bool operator !=(const HugeN &other);
};
HugeN HugeN::operator +(const HugeN &other)
{
HugeN temp;
temp.x[0]=x[0] > other.x[0] ? x[0]:other.x[0];
int tr=0,aux,i;
for(i=1;i<=temp.x[0];i++)
{
aux=x[i]+other.x[i]+tr;
temp.x[i]=aux%BASE;
tr=aux/BASE;
}
if(tr)
temp.x[++temp.x[0]]=tr;
return temp;
}
HugeN HugeN::operator + (long long k)
{
HugeN hk(k);
HugeN temp;
temp.x[0]=x[0];
temp=hk+*this;
return temp;
}
long long HugeN::operator %(long long k)
{
long long i,r=0;
for(i=x[0];i>=1;i--)
r=(r*10+x[i])%k;
return r;
}
int main()
{
freopen("next.in","r",stdin);
freopen("next.out","w",stdout);
HugeN M;
long long D,r;
char s[MAX_DIGITS+5];
scanf("%s",&s);
HugeN N(s);
scanf(" %lld ",&D);
r= N%D ;
if(r!=0)
N=N+(D-r);
N.print();
return 0;
}