Pagini recente » Cod sursa (job #555526) | Cod sursa (job #865415) | Cod sursa (job #2732579) | Cod sursa (job #1663222) | Cod sursa (job #1363891)
#include <iostream>
#include <fstream>
#include <cmath>
#define NMax 1000000000
using namespace std;
ifstream f("cmmdc.in");
ofstream g("cmmdc.out");
int fact(int x)
{
int nr=0,p=5;
while (x>=p)
{
nr+=x/p;
p*=5;
}
return nr;
}
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=fact(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;
}
}