Mai intai trebuie sa te autentifici.
Cod sursa(job #2295077)
| Utilizator | Data | 3 decembrie 2018 02:49:42 | |
|---|---|---|---|
| Problema | Factorial | Scor | 10 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.48 kb |
#include <fstream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int p;
int fact(int n)
{ int i,val=0;
for(i=5; n/i>=1; i*=5)
val+=n/i;
return val;
}
int main()
{ fin>>p;
if(p==0) {fout<<1; return 0;}
else if(p==1) {fout<<5; return 0;}
long long s=0,d=5*p;
int pp=0;
long long m=-1;
while(s<d )
{ m=(s+d)/2;
if(fact(m)==p) d=m;
else s=m+1;
}
fout<<m;
return 0;
}
