Pagini recente » Cod sursa (job #169501) | Cod sursa (job #2929759) | Cod sursa (job #3132234) | Cod sursa (job #3238969) | Cod sursa (job #1169337)
#include <iostream>
#include <fstream>
using namespace std;
int first, last, p, mid;
int nrzero(int x)
{
int p5 = 5;
int d = 0;
while (x/p5 != 0)
{
d += (x/p5);
p5*=5;
}
return d;
}
ifstream fin("fact.in");
ofstream fout("fact.out");
int main()
{
fin>>p;
first = 1; last =100000000;
while (first<=last)
{
mid = first + (last-first)/2;
if (nrzero(mid)<p)
first = mid + 1;
else last = mid - 1;
}
if(nrzero(first)==p)
fout<<first;
else fout<<"-1";
return 0;
}