Pagini recente » Cod sursa (job #1568933) | Cod sursa (job #866664) | Cod sursa (job #1997025) | Cod sursa (job #2074184) | Cod sursa (job #321858)
Cod sursa(job #321858)
#include <stdio.h>
#include <string.h>
FILE *f,*s;
char v1[1000001];
int n[1000001],c[1000001],i,j;
long long m,r,d;
unsigned long rest (int A[1000001], long long X)
{
unsigned long R=0;
for (i=A[0];i;i--)
R=(10*R+A[i])%X;
return R;
}
void suma(int x[1000001], int y[1000001])
{
long long int T=0;
if(y[0]>x[0])
{
for (i=x[0]+1; i<=y[0]; i++) x[i]=0;
x[0]=y[0];
}
else
for (i=y[0]+1; i<=x[0]; i++) y[i]=0;
for (i=y[0]+1; i<=x[0]; i++) y[i]=0;
for (i=1;i<=x[0];i++)
{
x[i]+=y[i]+T;
T=x[i]/10;
x[i]%=10;
}
if (T)
{
x[0]++;
x[x[0]]=T;
}
}
int main()
{
f=fopen("next.in","r");
s=fopen("next.out","w");
fscanf(f,"%s\n",&v1);
n[0]=strlen(v1);
j=1;
for(i=n[0]-1;i>=0;i--)
{
n[j]=v1[i]-48;
j++;
}
fscanf(f,"%lld",&m);
r=rest(n,m);
d=m-r;
c[0]=0;
while(d)
{
c[0]++;
c[c[0]]=d%10;
d/=10;
}
suma(n,c);
for(i=n[0];i>0;i--)
fprintf(s,"%d",n[i]);
fclose(s);
return 0;
}