Cod sursa(job #871986)
| Utilizator | Data | 5 februarie 2013 17:29:54 | |
|---|---|---|---|
| Problema | Factorial | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.57 kb |
#include <fstream>
using namespace std;
int main()
{
int n,p,k,a,l,h,sol;
ifstream fin("fact.in");
fin>>p;
fin.close();
sol = -1;
l = 1;
h = 2000000000;
while(l<=h)
{
n=(l+h)/2;
k = 0;
for (a = 5;a <= n; a *= 5)
k = k + n / a;
if (k == p)
{
sol = n;
h = n - 1;
}
else if (k > p) h = n - 1;
else l = n + 1;
}
ofstream fout("fact.out");
fout<<sol;
fout.close();
return 0;
}
