Cod sursa(job #862902)

Utilizator okros_alexandruOkros Alexandru okros_alexandru Data 23 ianuarie 2013 00:21:45
Problema Next Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <fstream>
#include <cstring>
#include <cmath>
#define nmax 1000100
using namespace std;

int N,A[nmax];
char S[nmax];
long long D;


void solve() {

    int i;
    long long Rest;

    for(N=strlen(S+1),i=N,Rest=0;i>=1;A[i]=(S[N-i+1]-48),Rest=(Rest*10LL+A[i--])%D);

    for(Rest=(D-Rest),i=1;Rest;A[i]+=Rest%10,Rest/=10,Rest+=A[i]/10,A[i++]%=10);

    for(N=max(N,i-1);false;);

}
void read() {

    ifstream in("next.in");
    in.getline(S+1,nmax);
    in>>D;
    in.close();

}
void write() {

    ofstream out("next.out");
    for(int i=N;i>=1;out<<A[i--]);
    out<<'\n';
    out.close();

}
int main() {

    read();
    solve();
    write();

    return 0;

}