Cod sursa(job #42840)

Utilizator ionescu_bogdanIonescu Bogdan-Gabriel ionescu_bogdan Data 29 martie 2007 16:07:51
Problema Next Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.6 kb
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define cmax 1000//050

int n[cmax],i;
long long d;
char s[cmax];

void divide()
{
	long long x=0;
	for (i=n[0];i>0;i--)
	{
		x=x*10+n[i];
		x%=d;
	}
	if (x)
	{
		n[1]+=d-x;
		i=1;
		while (n[i]>10)
			n[i+1]+=n[i]/10,n[i]%=10;
		if (i>n[0])
			n[0]=i;
	}
}

int main()
{
	freopen("next.in","r",stdin);
	freopen("next.out","w",stdout);

	scanf("%s%lld",s,&d);
	n[0]=strlen(s);
	for (i=0;i<n[0];i++)
		n[i+1]=s[n[0]-i-1]-'0';
	divide();
	for (i=n[0];i>0;i--)
		printf("%d",n[i]);
	printf("\n");

	return 0;
}