Cod sursa(job #1843826)
| Utilizator | Data | 9 ianuarie 2017 14:07:26 | |
|---|---|---|---|
| Problema | Factorial | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.6 kb |
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream in("fact.in");
ofstream out("fact.out");
long long st=1,dr=1000000000,mid,ct,p,fi=-1;
in>>p;
while(st<=dr)
{
mid=(st+dr)/2;
ct=0;
for(int i=5;i<=mid;i=i*5)
ct+=(mid/i);
if(p==ct)
{
fi=mid;
dr=mid-1;
}
else
{
if(ct<p)
{
st=mid+1;
}
else
dr=mid-1;
}
}
out<<fi;
return 0;
}
