Cod sursa(job #2661744)

Utilizator InfoFabianaFabiana Maria InfoFabiana Data 22 octombrie 2020 17:12:01
Problema Next Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.06 kb
#include <iostream>
#include <fstream>
#include <cstring>

using namespace std;

ifstream fin ("next.in");
ofstream fout ("next.out");

const int MAXN = 1000004;

struct Huge
{
    int data[MAXN];
};

void create_huge (Huge& nr, char x[])
{
    int sz=strlen(x);
    nr.data[0] = sz;
    for(int i = sz; i >= 1; i--)
        nr.data[i] = x[sz - i] - '0';
}
void print(const Huge &h)
{
    for (int i = h.data[0]; i >= 1; i--)
        fout<<h.data[i];
}

long long mod (Huge &h, long long d)
{
    long long x = 0;
    for(int i = h.data[0]; i >= 1; i--)
        x = (x * 10 + h.data[i]) % d;
    return x;
}
char s[MAXN];
long long d;
Huge N;
int main()
{
    fin.getline (s, MAXN);
    create_huge(N, s);
    fin>>d;
    long long add = d - mod(N, d);
    if(add == d)
        add=0;
    for(int i = 1; i <= N.data[0]; i++)
    {
        add += N.data[i];
        N.data[i] = add%10;
        add /= 10;
    }
    while(add)
    {
        N.data[++N.data[0]] = add%10;
        add /= 10;
    }
    print(N);

    return 0;
}