Cod sursa(job #1911311)

Utilizator ianiIani Biro iani Data 7 martie 2017 20:05:05
Problema Next Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.83 kb
#include <iostream>
#include <fstream>
#include <string.h>

using namespace std;

unsigned long long int n[1000001],d;

int main()
{
    ifstream fin ("next.in");
    ofstream fout ("next.out");
    char cit[1000001];
    fin.getline(cit,1000001);
    n[0]=strlen(cit);
    for (int i=n[0]-1; i>=0; i--)
        n[n[0]-i]=cit[i]-'0';
    fin>>d;
    unsigned long long int rest=0;
    for (unsigned int i=n[0]; i>0; i--)
        rest=(10*rest+n[i])%d;
    if (rest==0)
        fout<<cit;
    else
    {
        unsigned long long int T=0;
        n[1]=n[1]+d-rest;
        for (unsigned int i=1; i<=n[0]; i++)
        {
            n[i]+=T;
            T=n[i]/10;
            n[i]%=10;
        }
        if (T) n[++n[0]]=T;
        for (unsigned int i=n[0]; i>=1; i--)
            fout<<n[i];
    }
    return 0;
}