Cod sursa(job #1012049)
| Utilizator | Data | 17 octombrie 2013 22:16:25 | |
|---|---|---|---|
| Problema | Factorial | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.62 kb |
#include <fstream>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
int P;
int Solve(int fin)
{
int current=5,sol=0;
while(current<=fin)
{
sol+=fin/current;
current*=5;
}
return sol;
}
void Binary_Search()
{
long long st=1,dr=2000000000,mid,sol=-1;
while(st<=dr)
{
mid=(st+dr)/2;
int aux=Solve(mid);
if(aux<P)
st=mid+1;
if(aux>P)
dr=mid-1;
if(aux==P)
sol=mid,dr=mid-1;
}
g<<sol<<"\n";
}
int main()
{
f>>P;
Binary_Search();
return 0;
}
