Pagini recente » Cod sursa (job #1457757) | Cod sursa (job #2002460) | Cod sursa (job #1037261) | Cod sursa (job #572084) | Cod sursa (job #490759)
Cod sursa(job #490759)
#include<cstdio>
typedef int Huge[1<<20];
Huge a,b;
long long r,x;
void read()
{
freopen("next.in","r",stdin);
freopen("next.out","w",stdout);
char s[1<<20];
gets(s);
for(int i=0;s[i];i++)
a[++a[0]]=s[i]-'0';
scanf("%lld",&x);
}
long long modulo(Huge A,long long x)
{
long long T=0;
for(int i=1;i<=A[0];i++)
{
T=T*10+A[i];
if(T>=x)
T-=(T/x)*x;
}
return T;
}
void sch(int &X,int &Y)
{
int aux=X;
X=Y;
Y=aux;
}
void rastorn(Huge A)
{
int dr,st;
dr=0;
st=A[0]+1;
while(dr+1<st-1)
{
dr++;
st--;
sch(A[dr],A[st]);
}
}
void getvc(long long x,Huge A)
{
while(x)
A[++A[0]]=x%10, x/=10;
}
void adun(Huge A,Huge B)
{
int T=0,i=0;
for(i=1;i<=A[0] || i<=B[0];i++)
{
A[i]+=B[i]+T;
T=A[i]/10;
A[i]%=10;
}
A[0]=i-1;
while(A[A[0]]>9)
{
A[A[0]+1]=A[A[0]]%10;
A[A[0]]/=10;
A[0]++;
}
}
void afis(Huge A)
{
for(int i=A[0];i>=1;i--)
printf("%d",A[i]);
}
int main()
{
read();
r=modulo(a,x);
rastorn(a);
getvc(x-r,b);
adun(a,b);
afis(a);
return 0;
}