Mai intai trebuie sa te autentifici.
Cod sursa(job #1705087)
Utilizator | Data | 19 mai 2016 21:42:56 | |
---|---|---|---|
Problema | Factorial | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.62 kb |
#include <fstream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int n;
int Rezolvare(int x)
{
int s=0,y=5;
while(y<=x)
{
s=s+x/y;
y=y*5;
}
return s;
}
int CautBin(int y)
{
int st=1,dr=2073741824,m,poz=0;
while(st<=dr)
{
m=(st+dr)/2;
if(Rezolvare(m)==y)
poz=m;
if(Rezolvare(m)<y)
st=m+1;
else if(Rezolvare(m)>=y)
dr=m-1;
}
return poz;
}
int main()
{
fin>>n;
if(CautBin(n)==0)
fout<<"-1"<<"\n";
else
fout<<CautBin(n)<<"\n";
}