Pagini recente » Cod sursa (job #2861559) | Cod sursa (job #553067) | Cod sursa (job #1641263) | Cod sursa (job #678726) | Cod sursa (job #1687108)
#include<iostream>
#include<fstream>
#include<algorithm>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
int zero(int x)
{
int p5 = 5;
int d = 0;
while (x/p5 != 0) {
d =d+ (x/p5);
p5=p5*5;
}
return d;
}
int P;
int main()
{
int P,last,first,mid;
f>>P;
first = 1; last = 6*P;
while (first<=last) {
mid = first + (last-first)/2;
if (zero(mid)>=P)
last = mid - 1;
else
first = mid + 1;
}
if(zero(first)==P)
g<<first;
else
g<<"-1";
}