Cod sursa(job #2707737)
Utilizator | Bianca Lautaru biancalautaru | Data | 17 februarie 2021 17:35:12 |
---|---|---|---|
Problema | Factorial | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.51 kb |
#include <fstream>
#include <climits>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int p,st,dr,mid,x,i;
int main() {
fin>>p;
st=1;
dr=INT_MAX;
while (st<=dr) {
mid=(st+dr)/2;
x=0;
for (i=5;i<=mid;i*=5)
x+=mid/i;
if (x<p)
st=mid+1;
else
dr=mid-1;
}
x=0;
for (i=5;i<=st;i*=5)
x+=st/i;
if (x==p)
fout<<st;
else
fout<<-1;
return 0;
}