Cod sursa(job #612039)
| Utilizator | Data | 5 septembrie 2011 15:29:03 | |
|---|---|---|---|
| Problema | Factorial | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.43 kb |
#include <iostream>
#include <fstream>
using namespace std;
int main (void) {
long long a, b, p, c, i, nr, f;
ifstream q("fact.in");
ofstream g("fact.out");
n=0;
q>>p;
a=0;
b=500000000;
nr=0;
while (a!=b) {
f=1;
c=(a+b)/2;
for (i=1;i<c;i++)
f=f*i;
while (f!=0)nr=f/5;
if (nr==p) n=nr;
if (nr<p) a=c+1;
if (nr>p) b=c-1;}
if (n==0) g<<-1;
else g<<n;
f.close ();
g.close ();
return 0;}