Pagini recente » Cod sursa (job #2987128) | Cod sursa (job #132176) | Cod sursa (job #1780953) | Cod sursa (job #2848585) | Cod sursa (job #2770031)
#include <fstream>
#include <algorithm>
#include <cstring>
using namespace std;
ifstream fin("next.in");
ofstream fout("next.out");
const int MAXDIGITS = 1000005;
const int BASE = 10;
char s[MAXDIGITS];
class HUGE
{
private:
int x[MAXDIGITS];
public:
void print()
{
for(int i=x[0]; i>0; i--)
fout << x[i];
fout << '\n';
}
HUGE (char s[MAXDIGITS])
{
int n, i;
memset(x, 0, sizeof(x));
n=strlen(s);
x[0]=n;
for(i=1; i<=x[0]; i++)
{
x[i]=s[n-i]-'0';
}
}
// Supraincarcarea operatorilor aritmetici
HUGE operator += (long long &a);
long long operator % (int k);
};
HUGE HUGE::operator += (long long &a)
{
// x = x + other.x;
int i, tr, aux;
for(i=1, tr=0; i<=x[0]; i++)
{
aux = x[i] + a % 10 + tr;
x[i] = aux % BASE;
tr = aux / BASE;
a/=10;
}
if(tr)
x[++x[0]] = tr;
return (*this);
}
long long HUGE::operator % (int k)
{
int i, r=0;
for (i=x[0]; i>=1; i--)
{
r = r * 10 + x[i];
r = r % k;
}
return r;
}
int main()
{
ios_base::sync_with_stdio(0);
fin.tie(0);
long long d, r, aux;
fin >> s >> d;
HUGE a(s);
r = a % d;
if(!r)
a.print();
else
{
aux = d - r;
a += aux;
a.print();
}
return 0;
}