Cod sursa(job #55836)
| Utilizator | Data | 28 aprilie 2007 14:43:37 | |
|---|---|---|---|
| Problema | Factorial | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.52 kb |
#include <fstream.h>
ifstream fin ("fact.in");
ofstream fout ("fact.out");
int main() {
int p, nz, b, stanga=0, dreapta=1000000000, mijloc, gasit=0;
fin >> p;
if (p) {
while (!gasit && stanga<=dreapta) {
mijloc=(stanga+dreapta)/2;
b=5, nz=0;
while (b<=mijloc) {
nz+=mijloc/b;
b*=5;
}
if (nz==p) gasit=1;
else
if (nz>p) dreapta=mijloc-1;
else stanga=mijloc+1;
}
if (gasit) fout << mijloc-mijloc%5;
else fout << "-1";
}
else fout << '1';
fout.close();
return 0;
}