Pagini recente » Cod sursa (job #2787852) | Cod sursa (job #576232) | Cod sursa (job #3282270) | Cod sursa (job #2365918) | Cod sursa (job #1684923)
#include <iostream>
#include <fstream>
#define NMax 1000000000
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
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,val;
f>>p;
if (p==0) g<<1;
else
{
int min=1,max=NMax,mid;
bool ok=false;
while (min<=max && !ok)
{
mid=(min+max)/2;
val=fct(mid);
if (val<p) min=mid+1;
else if (val>p) max=mid-1;
else ok=true;
}
if (ok)
{
while (mid%5) mid--;
g<<mid;
}
else g<<-1;
}
}