Pagini recente » Diferente pentru implica-te/extinde-arhiva/autor-necunoscut intre reviziile 2 si 11 | Diferente pentru runda/franceza intre reviziile 4 si 2 | Cod sursa (job #2143574) | Cod sursa (job #1281625) | Cod sursa (job #705718)
Cod sursa(job #705718)
#include <cstdio>
#include <cstring>
#define NMax 1000010
#define LL long long
using namespace std;
int N[NMax]; char Number[NMax];
LL M;
inline LL Modulo (int A[], LL B)
{
LL Mod=0;
for (int i=A[0]; i>0; --i)
{
Mod=(10*Mod+A[i])%B;
}
return Mod;
}
inline void Add (int A[], LL B)
{
int i; LL T=B;
for (i=1; i<=A[0] or T>0; ++i, T/=10)
{
A[i]=(T+=A[i])%10;
}
A[0]=i-1;
}
void Read ()
{
freopen ("next.in", "r", stdin);
scanf ("%s\n%I64d", Number, &M);
N[0]=strlen (Number);
for (int i=1; i<=N[0]; ++i)
{
N[i]=Number[N[0]-i]-'0';
}
}
void Print ()
{
freopen ("next.out", "w", stdout);
for (int i=N[0]; i>0; --i)
{
printf ("%d", N[i]);
}
printf ("\n");
}
int main ()
{
Read ();
LL Mod=Modulo (N, M); if (Mod!=0) Mod=M-Mod;
Add (N, Mod);
Print ();
return 0;
}