Cod sursa(job #2332714)
Utilizator | Data | 31 ianuarie 2019 08:53:34 | |
---|---|---|---|
Problema | Factorial | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva de probleme | Marime | 0.51 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("fact.in");
ofstream out("fact.out");
int p,x,s;
int main()
{
in>>p;
int st=1,dr=1000000000,mij;
while(st<dr)
{
mij=(st+dr)/2;
x=mij;
s=0;
while(x)
{
s+=x/=5;
}
if(s>=p)dr=mij;
else st=mij+1;
}
int aux=dr,rez=0;
while(aux)
{
rez+=aux/=5;
}
if(rez==p)out<<dr;
else out<<-1;
return 0;
}