Cod sursa(job #1236786)

Utilizator PaueyPaula Nicoleta Gradu Pauey Data 2 octombrie 2014 16:35:20
Problema Next Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.68 kb
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <fstream>
using namespace std;

const int NMAX = 1000001;
const int BASE = 10;
string s;
ifstream in("next.in");
ofstream out("next.out");


class HUGE
{
    private: int x[NMAX];
    public: HUGE(){
                memset(x, 0, sizeof(x));
                x[0] = 1;
            }
            HUGE(string s) {
                memset(x, 0, sizeof(x));
                x[0] = s.size();
                for(int i = 0; i < x[0]; ++i) {
                    x[x[0] - i] = s[i] - '0';
                }
            }
            HUGE &operator += (long long &other) {
                long long tr = 0, k;
                for(int i = 1; i <= x[0]; ++i) {
                    k = x[i] + other % 10 + tr;
                    x[i] = k % BASE;
                    tr = k / BASE;
                    other = other /10;
                }
                if(tr) {
                    ++x[0];
                    x[x[0]] = tr % BASE;
                    tr = tr / BASE;
                }
                return *this;
            }
            long long &operator % (long long &other) {
                long long r = 0;
                for(int i = x[0]; i > 0; --i){
                    r = r * 10 + x[i];
                    r %= other;
                }
                return r;
            }
            void print(){
                for(int i = x[0]; i >= 1; --i)
                    out << x[i];
            }
};
int main()
{
    in >> s;
    HUGE N(s);
    long long D, R;
    in >> D;
    R = N % D;
    if(R > 0)
        R = D - R;
    N += R;
    N.print();
    return 0;
}