Cod sursa(job #270863)

Utilizator ssergiussSergiu-Ioan Ungur ssergiuss Data 4 martie 2009 17:54:35
Problema Next Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.8 kb
//#include<algorithm>
//using namespace std;
#include<stdio.h>
short a[1000001],b[21];
long long d;
void adun(){
    int i,t;
    for(i=1; i<=a[0]||i<=b[0]||t; t/=10,++i)
        a[i]=(t+=a[i]+b[i])%10;
    a[0]=i-1;}
void trans(long long x){
    for(; x; b[++b[0]]=x%10,x/=10);}
long long rest(){
    int i;
    long long t;
    for(i=a[0]; i; --i)
        t=(t*10+a[i])%d;
    return t;}
void solve(){
	int i,j,aux;
	char ch;
	for(scanf("%c",&ch); ch!='\n'; a[++a[0]]=ch-'0',scanf("%c",&ch));
	for(i=1,j=a[0]; i<j; ++i,--j){
		aux=a[i];
		a[i]=a[j];
		a[j]=aux;}
    scanf("%lld",&d);
    trans((d-rest())%d);
    adun();
    for(i=a[0]; i; --i)
        printf("%hd",a[i]);}
int main(){
    freopen("next.in","r",stdin);
    freopen("next.out","w",stdout);
    solve();
    return 0;}