Pagini recente » Cod sursa (job #2860246) | Cod sursa (job #1924979) | Cod sursa (job #2969293) | Cod sursa (job #193531) | Cod sursa (job #1236725)
#include <cstdio>
#include <cstring>
using namespace std;
const int MAX=1000000,BASE=10;
char s[MAX];
bool ok;
class HUGE
{
private:
int x[MAX];
public:
void scan()
{
scanf("%s",s);
int n=strlen(s);
x[0]=n;
for(int i=n-1;i>=0;--i)
x[n-i]=s[i]-'0';
}
void print()
{
for(int i=x[0];i>=1;--i)
printf("%d",x[i]);
}
void copy(const HUGE & other)
{
x[0]=other.x[0];
for(int i=1;i<=x[0];++i)
x[i]=other.x[i];
}
void adunare(long long a)
{
int rest=0,i=1;
x[i]+=a;
rest=x[i]/BASE,x[i]%=BASE;
while(rest)
{
i++;x[i]+=rest;
rest=x[i]/BASE,x[i]%=BASE;
}
if(i>x[0])x[0]=i;
}
long long impartire(long long d)
{
long long rest=0;
for(int i=x[0];i>=1;--i)
{
rest=rest*BASE+x[i];
x[i]=rest/d,rest%=d;
}
return rest;
}
};
HUGE a,b;
int main()
{
freopen("next.in","r",stdin);
freopen("next.out","w",stdout);
long long x,rest;
a.scan();
scanf("%lld",&x);
b.copy(a);
rest=b.impartire(x);
if(rest)
a.adunare(x-rest);
a.print();
return 0;
}