Cod sursa(job #2770703)

Utilizator AswVwsACamburu Luca AswVwsA Data 22 august 2021 19:12:26
Problema Next Scor 60
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.58 kb
#include <fstream>
#include <cstring>
using namespace std;
ifstream cin("next.in");
ofstream cout("next.out");
const int MAX_DIGITS=100003;
const int BASE=10;
class HUGE{
    private : int x[MAX_DIGITS];
    public :
        //constructori
        HUGE(){
        memset (x,0, sizeof(x));
            x[0]=1;
        }
        HUGE ( string s){
            memset(x,0,sizeof(x));
            x[0]=s.size();
            for (int j=s.size()-1,i=1;i<=x[0];++i,--j)
                x[i]=s[j]-'0';
        }
    HUGE(int n){
        memset(x,0,sizeof(x));
        x[0]=0;
        do{
            ++x[0];
            x[x[0]]=n%10;
            n/=10;
        }while (n);
    }
    void print (){
    for (int i=x[0];i>0;--i)
        cout<<x[i];
        cout<<"\n";
    }
    void operator += (const HUGE &other);
    long long  operator % ( long long n);
};
void  HUGE:: operator += (const HUGE&other){
    //x=x+other.x
    int i,tr, aux;
    x[0]=max(x[0], other.x[0]);
    for (i=1,tr=0;i<=x[0];++i)
    {
        aux=x[i]+other.x[i]+tr;
        x[i]=aux%BASE;
        tr=aux/BASE;
    }
    while (tr){
        x[0]++;
        x[x[0]]=tr%BASE;
        tr/=BASE;
    }
}
long long  HUGE :: operator % ( long long  k) {
      int i, t = 0;
      for (i = x[0]; i > 0; i--)
              t = (t * 10 + x[i]) % k;
      return t;
}
string s;
int main(){
    cin>>s;
   HUGE a(s);
   long long d;
   cin>>d;
   long long r= (a%d);
   if (!r)
        a.print();
   else {
        r=d-r;
        HUGE aux(r);
        a+=aux;
        a.print();
   }
}