Pagini recente » Cod sursa (job #2801527) | Cod sursa (job #955466) | Cod sursa (job #1306786) | Cod sursa (job #1814094) | Cod sursa (job #490763)
Cod sursa(job #490763)
#include<cstdio>
typedef int Huge[1<<20];
Huge a;
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];
T%=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 adun(Huge A,long long x)
{
long long aux,T=x;
int i;
for(i=1;i<=A[0] || T;i++)
{
aux=T+A[i];
A[i]=(int)((long long)aux%10);
T=aux/10;
}
A[0]=i-1;
}
void afis(Huge A)
{
for(int i=A[0];i>=1;i--)
printf("%d",A[i]);
}
int main()
{
read();
r=modulo(a,x);
if(r)
{
rastorn(a);
adun(a,x-r);
}
afis(a);
return 0;
}