Pagini recente » Cod sursa (job #61840) | Cod sursa (job #2292753) | Cod sursa (job #1869984) | Cod sursa (job #1104876) | Cod sursa (job #1784773)
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
const int MAX_DIGITS=1000001;
const int BASE=10;
//const int MAX_INT=(1LL << 31)-1;
char s[MAX_DIGITS+5];
using namespace std;
class HugeN
{
private:
int x[MAX_DIGITS+5];
public:
HugeN()
{
x[0]=1;
for(int i=1; i <= MAX_DIGITS; i++)
x[i]=0;
}
HugeN(int nr)
{
for(int i=0; i <= MAX_DIGITS; i++)
x[i]=0;
do
{
x[++x[0]] = nr%10;
}
while(nr);
}
HugeN(HugeN &other)
{
for(int i=0; i <= MAX_DIGITS; i++)
x[i]=0;
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()
{
int i;
for(i=x[0]; i >= 1; i--)
printf("%d", x[i]);
printf("\n");
}
bool null();
int nr_digits();
void atr_int(int nr);
void rev ();
void reset ();
void cpy_char(char *s);
int cmp(const HugeN &other);
//Operatori logici
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);
//Operatori aritmetici
HugeN operator +(const HugeN &other);
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);
HugeN operator +=(long long k);
};
int HugeN :: cmp (const HugeN &other)
{
int i;
if(x[0] > other.x[0])
return 1;
if(x[0]< other.x[0])
return -1;
for(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;
}
HugeN HugeN :: operator+(const HugeN &other)
{
int i,tr=0,aux;
HugeN temp;
temp.x[0]=x[0] > other.x[0] ? x[0] : other.x[0];
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+=(const HugeN &other)
{
x[0]=x[0] > other.x[0] ? x[0] : other.x[0];
int tr=0, aux, i;
for(i=1; i<=x[0]; i++)
{
aux=x[i]+other.x[i]+tr;
x[i]=aux%BASE;
tr=aux/BASE;
}
if(tr)
x[++x[0]]=tr;
return (*this);
}
HugeN HugeN :: operator+=(long long k)
{
long long aux,i;
for(i=1; i<=x[0]; i++)
{
aux=x[i]+k;
x[i]=aux%BASE;
k=aux/BASE;
}
if(k)
x[++x[0]]=k;
return *this;
}
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);
long long d,rest;
gets(s);
HugeN n(s);
scanf("%lld", &d);
rest=(d-n%d)%d;
n+=rest;
n.print();
return 0;
}
}