Cod sursa(job #2398253)

Utilizator iulianarsenoiuArsenoiu Iulian iulianarsenoiu Data 5 aprilie 2019 11:09:50
Problema Next Scor 40
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.95 kb
#include <fstream>
#include <algorithm>

using namespace std;
ifstream f("next.in");
ofstream g("next.out");
unsigned long long x,d,i;
int a[1000005];
bool ok;
char ch;
int rest(long long d)
{
    int t=0;
    long long i=0;
    for(i=a[0]; i>=1; i--)
    {
        t=t*10+a[i];
        t=t%d;
    }
    return t;
}
int main()
{
    while(f.get(ch))
    {
        if(ch=='\n')
            break;
        else
        {
            a[++a[0]]=ch-'0';
        }
    }
    f>>d;
    reverse(a+1,a+a[0]+1);
    while(ok==false)
    {
        if(rest(d)==0)
        {
            for(i=a[0]; i>=1; i--)
                g<<a[i];
            g<<'\n';
            break;
        }
        else
        {
            i=1;
            while(a[i]==9)
            {
                a[i]=0;
                i++;
            }
            a[i]++;
            if(i>a[0])
                a[0]=i;
        }
    }
    return 0;
}