Pagini recente » Cod sursa (job #2141224) | Cod sursa (job #828734) | Cod sursa (job #3037787) | Cod sursa (job #2025905) | Cod sursa (job #2883925)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int dv(int x){
int d = 5, p = 0;
while(x % d == 0) x /= d, p++;
if(p)
return p;
}
int64_t fact(int a){
int i; int64_t cnt = 0;
for(i = 5; i <= a; i+=5)
cnt += dv(i);
return cnt;
}
int n, st = 0, dr = 100000000, mij, gasit = 0;
int64_t k;
int main(){
fin >> n; if(n == 0) gasit = 1;
while(st <= dr && !gasit){
mij = (st + dr) / 2; k = fact(mij);
if(k == n) gasit = mij;
else if(n < k) dr = mij - 1;
else if(n > k) st = mij + 1;
}
if(gasit == 1 || gasit % 5 == 0) cout << gasit;
else{
for(int i = gasit; i >= 1; i--)
if(i % 5 == 0){
fout << i;
break;
}
}
if(gasit == 0) fout << -1;
}