Cod sursa(job #2808196)
| Utilizator | Data | 24 noiembrie 2021 18:18:58 | |
|---|---|---|---|
| Problema | Factorial | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.81 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin ("fact.in");
ofstream fout ("fact.out");
int p,l,r,m,exp,x,sol;
bool ok=1;
int main()
{
fin>>p;
l=1;
r=100000000;
if (p==0)
fout<<'1';
else
{
while (l<=r && ok)
{
m=(l+r)/2;
exp=0;
x=m;
while (x>0)
{
exp+=x;
x/=5;
}
if (exp<p)
{
l=m+1;
}
else if (exp>p)
{
r=m-1;
}
else
{
ok=0;
sol=m*5;
}
}
if (ok)
fout<<"-1";
else fout<<sol;
}
return 0;
}
