Mai intai trebuie sa te autentifici.
Cod sursa(job #1777568)
Utilizator | Data | 12 octombrie 2016 17:29:23 | |
---|---|---|---|
Problema | Next | Scor | 30 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 3.2 kb |
#include<bits/stdc++.h>
#define baza 1000000000000000
using namespace std;
long long v[1000005],d,v1[1000005],rest;
char s[1000005],buff[50];
long long restscalar(long long a[],long long n)
{
long long t=0;
for (long long i=a[0];i>=1;i--)
{
t=(t*baza+a[i])%n;
}
return t;
}
void adunare(long long a[],long long b[])
{
long long t=0,i;
for(i=1;i<=a[0] ||i<=b[0] ||t;i++)
{
t=t+a[i]+b[i];
a[i]=t%baza;
t/=baza;
}
a[0]=i-1;
}
void conversie(long long v[],long long x)
{
long long da=0;
while(x)
{
v[++da]=x%baza;
x/=baza;
}
v[0]=da;
}
void scrie(long long x)
{
if(x<10)
{
printf("00000000000000%lld",x);
return;
}
if(x<100)
{
printf("0000000000000%lld",x);
return;
}
if(x<1000)
{
printf("000000000000%lld",x);
return;
}
if(x<10000)
{
printf("00000000000%lld",x);
return;
}
if(x<100000)
{
printf("0000000000%lld",x);
return;
}
if(x<1000000)
{
printf("000000000%lld",x);
return;
}
if(x<10000000)
{
printf("00000000%lld",x);
return;
}
if(x<100000000)
{
printf("0000000%lld",x);
return;
}
if(x<1000000000)
{
printf("000000%lld",x);
return;
}
if(x<10000000000)
{
printf("00000%lld",x);
return;
}
if(x<100000000000)
{
printf("0000%lld",x);
return;
}
if(x<1000000000000)
{
printf("000%lld",x);
return;
}
if(x<10000000000000)
{
printf("00%lld",x);
return;
}
if(x<100000000000000)
{
printf("0%lld",x);
return;
}
printf("%lld",x);
}
void afisare(long long v[])
{
long long x=v[0];
//scrie(v[x]);
printf("%lld",v[x]);
for(long long i=x-1;i>=1;i--)
scrie(v[i]);
printf("\n");
}
int main()
{
freopen("next.in","r",stdin);
freopen("next.out","w",stdout);
scanf("%s",&s);
long long x=strlen(s);
long long z=x%15;
fclose(stdin);
freopen("next.in","r",stdin);
long long dv=0;
if(z)
{
memset(buff,0,20);
fread(buff,1,z,stdin);
long long y=0;
for(int i=0;i<z;i++)
{
y=y*10+(buff[i]-'0');
}
v[++dv]=y;
x-=z;
}
while(x>0)
{
{
memset(buff,0,20);
fread(buff,1,15,stdin);
// long long y=atol(buff);
// v[++dv]=atol(buff);
long long y=0;
for(int i=0;i<15;i++)
{
y=y*10+(buff[i]-'0');
}
v[++dv]=y;
x-=15;
}
}
reverse(v+1,v+dv+1);
v[0]=dv;
scanf("\n");
scanf("%lld",&d);
rest=restscalar(v,d);
if(!rest) rest=d;
rest=d-rest;
conversie(v1,rest);
adunare(v,v1);
x=v[0];
//scrie(v[x]);
printf("%lld",v[x]);
for(long long i=x-1;i>=1;i--)
scrie(v[i]);
printf("\n");
return 0;
}