Pagini recente » Cod sursa (job #1238717) | Istoria paginii runda/atafedtsorp/clasament | Cod sursa (job #2440167) | Cod sursa (job #1729105) | Cod sursa (job #1911301)
#include <iostream>
#include <fstream>
#include <string.h>
using namespace std;
unsigned long long int n[1000001],d;
int main()
{
ifstream fin ("next.in");
ofstream fout ("next.out");
char cit[1000001];
fin.getline(cit,1000001);
n[0]=strlen(cit);
for (int i=n[0]-1; i>=0; i--)
n[n[0]-i]=cit[i]-'0';
fin>>d;
unsigned long long int rest=0;
for (unsigned int i=n[0]; i>0; i--)
rest=(10*rest+n[i])%d;
if (rest==0)
fout<<cit;
else
{
unsigned long long int adun=d-rest;
unsigned long long int T=0;
n[1]+=adun;
for (unsigned int i=1; i<=n[0]; i++)
{
n[i]+=T;
T=n[i]/10;
n[i]%=10;
}
if (T) n[++n[0]]=T;
for (unsigned int i=n[0]; i>=1; i--)
fout<<n[i];
}
return 0;
}