Cod sursa(job #1239260)

Utilizator torckySuciu Victor torcky Data 8 octombrie 2014 17:08:24
Problema Next Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.91 kb
#include<cstdio>
#include<cstring>
#include<algorithm>
const int MAX_digits=1000020;
const int base=10;
using namespace std;
class hugeN
{
    private:
        int x[MAX_digits];
    public:
        hugeN()
        {
            memset(x,0,sizeof(x));
            x[0]=1;
        }
            hugeN(long long n)
        {
            memset(x,0,sizeof(x));
            x[0]=0;
            do
            {
                x[++x[0]]=n%10;
                n=n/10;
            }while(n);
        }
        hugeN(char *s)
        {
            memset(x,0,sizeof(x));
            int l,i;
            l=strlen(s);
            x[0]=l;
            for(i=l-1;i>=0;--i)
                x[l-i]=s[i]-'0';
        }
        hugeN (const hugeN&other)
        {
            memset(x,0,sizeof(x));
            for(int i=0;i<=other.x[0];++i)
                x[i]=other.x[i];
         }
         void print()
         {
             int i;
             for(i=x[0];i>=1;--i)
                printf("%d",x[i]);
            printf("\n");
         }
         long long operator%(long long k);
         hugeN& operator+=(long long k);
};

long long hugeN::operator %(long long k)
{
    long long r=0;
    int i;
    for(i=x[0];i>0;--i)
    {
        r=(long long)r*10+x[i];
        r=r%k;
    }
    return r;
}

hugeN& hugeN:: operator +=(long long k)
{
    int i;
    long long t = k;
    for (i=1;i<=x[0]; ++i)
       {
        t = t +x[i];
        x[i] = t%10;
        t = t/10;
       }
    while(t)
    {
        x[0]++;
        x[x[0]]=t % 10;
        t=t/10;
    }
   return *this;
}
char s[1000005];
int main()
{
    freopen("next.in","r",stdin);
    freopen("next.out","w",stdout);
    scanf("%s",s);
    hugeN n(s);
    long long d,r;
    scanf("%lld",&d);
    r=n%d;
    if (r)
    {


    d=d-r;
    //hugeN d2(d);

    n+=d;
    }
    n.print();
    return 0;
}