Cod sursa(job #1134068)
| Utilizator | Data | 5 martie 2014 22:43:39 | |
|---|---|---|---|
| Problema | Next | Scor | 20 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.67 kb |
#include <fstream>
#include <string.h>
using namespace std;
ifstream f("next.in");
ofstream g("next.out");
long long m,add,i,nr,r,rr;
char s[1000001];
int main()
{
f>>s>>m;
for (i=0;i<strlen(s);i++)
add=(add*10+s[i]-48)%m;
add=(m-add)%m;
//g<<add<<'\n';
nr=strlen(s)-1;
while (add)
{
if (add%10+s[nr]-48+r>=10)
rr=1;
else
rr=0;
s[nr--]=(add%10+s[nr]+r-48)%10+48;
r=rr;
add/=10;
}
if (rr)
if (s[0]<'9')
s[0]++;
else
{
g<<1;
s[0]=0;
}
g<<s;
f.close();
g.close();
}
