Pagini recente » Cod sursa (job #387768) | Statistici Dinu Gabriel (gabi_dinu) | Cod sursa (job #1963886) | Rating Rafael Tura (rafaeel) | Cod sursa (job #1236748)
#include <cstdio>
#include <algorithm>
#include <cstring>
const int MAX_DIGITS = 1<<10;
const int BASE = 10;
class HugeN
{
private:
int x[MAX_DIGITS];
public:
//constructori
HugeN()
{
memset(x,0,sizeof(x));
x[0]=1;
}
HugeN(int n)
{
memset(x,0,sizeof(x));
x[0] = 0;
do
{
x[++x[0]] = n%10;
n = n/10;
}while(n);
}
HugeN(char *s)
{
int n, i;
n = strlen(s);
x[0] = n;
for(i=n-1; i>=0; i--)
x[n-i] = s[i]-'0';
}
HugeN(const HugeN& other)
{
memcpy(x,other.x, sizeof(other.x));
}
void print()
{
for(int i =x[0]; i>=1; i--)
printf("%d",x[i]);
printf("\n");
}
//compararea a doua HugeN
int cmp(const HugeN& other)
{
//x ? other
if(x[0] < other.x[0]) return -1;
else if(x[0]>other.x[0]) return 1;
for(int i=x[0]; i>0; i--)
if(x[i] < other.x[i]) return -1;
else if(x[i] > other.x[i]) return 1;
return 0;
}
HugeN operator +=(int k);
long long operator %(long long k);
};
long long HugeN::operator % (long long k)
{
int r=0, i;
for(i=x[0]; i>0; i--)
{
r = r*10+x[i];
r %= k;
}
return r;
}
HugeN HugeN::operator+=(int k)
{
int t, i;
for(t=0, i=1; i<=x[0]; i++)
{
t = x[i] + k%10 + t;
x[i] = t%10;
t/= 10;
k /= 10;
}
if(t)
{
x[0]++;
x[x[0]]=t;
return *this;
}
}
int main()
{
freopen("next.in","r",stdin);
freopen("next.out","w",stdout);
char st[1000005];
long long x, r;
scanf("%s", st);
scanf("%lld", &x);
HugeN n(st);
r = n%x;
if(r)
{
r = x-r;
n += r;
}
n.print();
}