Cod sursa(job #2630602)
Utilizator | yarina yzara | Data | 26 iunie 2020 13:42:51 |
---|---|---|---|
Problema | Factorial | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.64 kb |
#include <fstream>
using namespace std;
ifstream in("fact.in");
ofstream out("fact.out");
long long st,dr,p;
int main()
{
in>>p;
st=1;
dr=5e8;
while ( st<=dr)
{
long long aux=(st+dr)/2;
long long rez=0;
while ( aux>0)
{
rez+=(aux/5);
aux/=5;
}
if ( rez>=p)
dr=(st+dr)/2-1;
else
st=(st+dr)/2+1;
}
long long aux=st;
long long rez=0;
while ( aux>0)
{
rez+=(aux/5);
aux/=5;
}
if ( rez==p)
out<<st;
else
out<<-1;
return 0;
}