Cod sursa(job #1236749)

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

const int NMAX = 1000001;
const int BASE = 10;

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;
                HUGE temp;
                temp.x[0] = x[0];
                for(int i = 1; i <= temp.x[0]; ++i) {
                    k = x[i] + other % BASE + tr;
                    temp.x[i] = k % BASE;
                    tr = k / BASE;
                    other = other / 10;
                }
                k = temp.x[0];
                if(tr) {
                    ++k;
                    temp.x[0] = k;
                    temp.x[k] = tr;
                }
                return temp;
            }
            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)
                    cout << x[i];
            }
};
int main()
{
    ifstream cin("next.in");
    ofstream cout("next.out");

    string s;
    cin >> s;
    HUGE N(s);
    long long D, R;
    cin >> D;
    HUGE ANS;
    R = N % D;
    if(R > 0)
        R = D - R;
    ANS = N + R;
    ANS.print();
    return 0;
}