Pagini recente » Cod sursa (job #572870) | Cod sursa (job #839570) | Cod sursa (job #598448) | Cod sursa (job #2354612) | Cod sursa (job #2489457)
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
ifstream fin ("next.in");
ofstream fout ("next.out");
const int MAXN=1000004;
struct Huge
{
int data[MAXN];
};
void create_huge (Huge& nr, char x[])
{
int sz=strlen(x);
nr.data[0]=sz;
for(int i=sz; i>=1; i--)
nr.data[i]=x[sz-i]-'0';
}
void print(const Huge &h)
{
for (int i = h.data[0]; i >= 1; i--)
fout << h.data[i];
}
long long mod (Huge &h, long long d)
{
long long x=0;
for(int i=h.data[0]; i>=1; i--)
x=(x*10+h.data[i])%d;
return x;
}
char s[MAXN];
long long d;
Huge N;
int main()
{
fin.getline (s, MAXN);
create_huge(N, s);
fin>>d;
long long add=d-mod(N, d);
if(add==d)
add=0;
for(int i=1; i<=N.data[0]; i++)
{
add+=N.data[i];
N.data[i]=add%10;
add/=10;
}
while(add)
{
N.data[++N.data[0]]=add%10;
add/=10;
}
print(N);
return 0;
}