Cod sursa(job #2080332)
Utilizator | Data | 2 decembrie 2017 19:54:32 | |
---|---|---|---|
Problema | Factorial | Scor | 85 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.56 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
int p;
int zero(int x)
{
int ans = 0;
while(x>=5)
ans+=(x/=5);
return ans;
}
int main()
{
f >> p;
int i = 1;
int ok = 0;
int m = 0;
int s = (1<<28);
while(i<=s)
{
m = (i+s)/2;
if(zero(m)==p)
{
ok=1;
g << m-(m%5);
break;
}
else if(zero(m)<p) i=m+1;
else if(zero(m)>p) s=m-1;
}
if(i>s) g << -1;
}