Pagini recente » Cod sursa (job #2969309) | Cod sursa (job #2116036) | Cod sursa (job #2743837) | Cod sursa (job #833153) | Cod sursa (job #1358726)
#include <fstream>
ifstream cin("fact.in");
ofstream cout("fact.out");
using namespace std;
int fct(int x)
{
int a=5,rez=0;
while (x/a)
{
rez=rez+x/a;
a=a*5;
}
return rez;
}
int main()
{
int p,valoare;
cin>>p;
if ( p==0 )
cout<<1;
else
{
int min=1,max=NMax,mid;
bool ok=false;
while(min<=max && !ok)
valoare=fct(mid);
if (valoare<p) min=mid+1;
else if (valoare>p) max=mid-1;
else ok=true;
}
if ( ok )
{
while (mid%5) mid--;
cout<<mid;
}
else cout<<-1;
return 0;
}