Cod sursa(job #1039201)

Utilizator Athena99Anghel Anca Athena99 Data 22 noiembrie 2013 17:52:07
Problema Next Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.75 kb
#include <cassert>
#include <cstdio>
#include <cstring>

const int nmax= 1000000;

long long v[nmax+1];
char s[nmax+1];

int main(  ) {
    assert( freopen( "next.in", "r", stdin ));
    assert( freopen( "next.out", "w", stdout ));

    assert( scanf("%s", &s));
    int x= strlen(s)-1;
    for ( int i= x; i>=0; --i ) {
        v[x-i]= s[i]-'0';
    }

    long long d;
    assert(scanf( "%lld", &d ));

    long long t= 0;
    for ( int i= x; i>=0; --i ) {
        t= (t*10+v[i])%d;
    }
    t= (d-t)%d;
    for ( int i= 0; i<=x || t>0; ++i ) {
        if ( i>x ) {
            ++x;
        }
        v[i]+= t;
        t= v[i]/10;
        v[i]%= 10;
    }
    for ( int i= x; i>=0; --i ) {
        printf( "%lld", v[i] );
    }
    printf( "\n" );

    return 0;
}