Pagini recente » preONI 2008 - Runda 2 | preONI 2008 - Runda 3, Clasa a 10-a | preONI 2008 - Runda 1, Clasa a 10-a | Monitorul de evaluare | Cod sursa (job #2724914)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int f(int x){
int t=x;
while(x){
x /= 5;
t+=x;
}
return t;
}
int main() {
int x;
fin>>x;
if(x == 0){
fout << 1;
return 0;
}
int lt=1;
int mid, y;
int right = x;
while(lt<=right){
mid = lt+(right-lt)/2;
y=f(mid);
if(y==x) {
lt = mid;
break;
}
if(y<x){
lt = mid + 1;
} else {
right = mid - 1;
}
}
if(f(lt) == x){
fout << lt*5;
} else {
fout << -1;
}
return 0;
}