Cod sursa(job #490762)

Utilizator dushmiMihai-Alexandru Dusmanu dushmi Data 7 octombrie 2010 19:23:36
Problema Next Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.05 kb
#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);
    rastorn(a);
    adun(a,x-r);
    afis(a);
    return 0;
}