Cod sursa(job #2069889)

Utilizator adiaioanaAdia R. adiaioana Data 18 noiembrie 2017 22:17:09
Problema Next Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.08 kb
#include <fstream>
#define nm 1000001
#include <cstring>
using namespace std;
ifstream fin("next.in");
ofstream fout("next.out");

unsigned long long x;
int N[nm],ind;
char n[nm];
void transf(char s[nm], int S[nm]);
int rest(int S[nm],unsigned long long y);
void print(int S[nm]);
int main()
{
    fin>>n;
    transf(n,N);
    fin>>x;
    while(1)
    {
        if(rest(N,x)==0)
        {
            print(N);
            return 0;
        }
        N[1]++;
        if(N[1]>9)
        {
            N[1]=9;
            ind=1;
            while(N[ind]==9)
                N[ind]=0,ind++;
            N[ind]++;
            if(ind==N[0]+1)
                N[0]++;
        }
    }
    return 0;
}
void print(int S[nm])
{
    for(int i=S[0];i>0;i--)
        fout<<S[i];
    fout<<'\n';
}
int rest(int S[nm],unsigned long long y)
{
    unsigned long long R=0;
    for(int i=S[0];i>0;i--)
        R=(R*10+S[i])%y;
    return R;
}
void transf(char s[nm], int S[nm])
{
    int lg=strlen(s);
    for(int i=0;i<lg;i++)
        S[lg-i]=s[i]-'0';
    S[0]=lg;
}