Pagini recente » Cod sursa (job #3172366) | Cod sursa (job #2667659) | Cod sursa (job #125522) | Cod sursa (job #2632737) | Cod sursa (job #1236795)
#include <cstdio>
#include <cstring>
using namespace std;
const int MAX=900000,BASE=10;
char s[MAX];
class HUGE
{
private:
int x[MAX];
public:
void scan()
{
memset(x,0,sizeof(x));
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=0;
while(a)
{
i++;
x[i]=x[i]+a%BASE+rest;
a/=BASE;
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)
{
rest=x-rest;
a.adunare(rest);
}
a.print();
return 0;
}