Pagini recente » Cod sursa (job #2510901) | Cod sursa (job #924621) | Cod sursa (job #2329306) | Cod sursa (job #193161) | Cod sursa (job #66658)
Cod sursa(job #66658)
#include<stdio.h>
#include<iostream>
#include<string.h>
long long d, r, aux, lung;
int *a=new int[500010];
int *b=new int[170];
void citire()
{
char s[500010];
freopen("next.in","r",stdin);
scanf("%s",&s);
long long l;
l=strlen(s);
for (long long i=l-1; i>=0; i--)
a[l-i]=s[i]-'0';
lung=l;
a[0]=l;
scanf("%lld",&d);
}
long long mod(int A[], long long B)
{
long long i, t = 0;
for (i = lung; i > 0; i--)
t = (t * 10 + A[i]) % B;
return t;
}
void adunare()
{ int ct;
int *s=new int [500040];
long long i;
ct = 0;
memset (s, 0, sizeof(s));
/*if (a[0]>b[0]) s[0] = a[0];
else s[0]=b[0];
for (i = 1; i <= s[0]; i++)
{ s[i] = a[i] + b[i] + ct;
ct = s[i] / 10;
s[i] = s[i] % 10;
}
if (ct) { s[0]++;
s[s[0]] = ct;
}*/
freopen("next.out","w",stdout);
for (i=s[0]; i>=1; i--)
printf("%d",s[i]);
}
void transform()
{
b[0]=0;
while (aux)
{
b[0]++ ;
b[b[0]]=aux%10;
aux/=10;
}
}
int main()
{
citire();
r=mod(a,d);
aux=(d-r)%d;
transform();
adunare();
return 0;
}