Cod sursa(job #2395213)
Utilizator | Boni Daniel Stefan refugiat | Data | 2 aprilie 2019 12:36:13 |
---|---|---|---|
Problema | Factorial | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.92 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream si("fact.in");
ofstream so("fact.out");
int main()
{
int st,dr,mij,p,e,aux,p5,rez,t=0;
si>>p;
st=1;
dr=5*p;
while(st<=dr)
{
mij=(st+dr)/2;
aux=mij;
e=0;
while(aux)
{
aux/=5;
e+=aux;
}
if(e<p)
{
st=mij+1;
}
else
{
if(e==p)
{
rez=mij;
dr=mij-1;
t++;
}
else
{
if(e>p)
{
dr=mij-1;
}
}
}
}
if(t>0 && p>0){
so<<rez;
}
else{
if(p==0){
so<<"1";
}
else{
if(t==0) so<<"-1";
}
}
return 0;
}