Pagini recente » Cod sursa (job #377266) | Cod sursa (job #1327610) | Cod sursa (job #819103) | Cod sursa (job #1022174) | Cod sursa (job #2927519)
#include<bits/stdc++.h>
std::ifstream in("fact.in");
std::ofstream out("fact.out");
float log5(int x){
return (float)log2(x)/log2(5);
}
float cat5(int x){
float ret = 0;
ret = (float)x/5;
for(int i = 25; i<=x; i *= 5){
ret ++;
}
return ret;
}
int main(){
int n; in>>n;
//binary search from 1 to MAX_INT aprox 32 steps, constant time searching
unsigned int x = 0, y = INT_MAX;
while(x < y){
int m = (x+y)/2;
if(cat5(m) > n) y = m - 1;
else if(cat5(m) < n) x = m + 1;
else{
out<<m;
return 0;
}
}
out<<-1;
}