Pagini recente » Cod sursa (job #2062483) | Cod sursa (job #1304063) | Cod sursa (job #1386461) | Cod sursa (job #2559715) | Cod sursa (job #1647086)
#include <iostream>
#include <cstdio>
const char inFile[] = "fact.in";
const char outFile[] = "fact.out";
const unsigned long long inf = 1<<61;
using namespace std;
unsigned long long p, n;
int main()
{
unsigned long long a, b, mid, x, y;
freopen(inFile, "r", stdin);
freopen(outFile, "w", stdout);
b = inf;
scanf("%d", &p);
if(p == 0) printf("%d", 1);
if(p == 1) printf("%d", 5);
while(a <= b){
mid = (a + b) / 2;
x = 5;
y = 0;
while(x <= 5 * mid) {
y += mid / x;
x = 5 * x;
}
if(p == y) {
while(mid % 5 != 0)
mid--;
break;
}
else{
if(p > y)
a = mid + 1;
else
b = mid - 1;
}
}
if(a <= b)
printf("%d", mid);
else
printf("%d", -1);
}