Pagini recente » Cod sursa (job #1753881) | Cod sursa (job #1450385) | Cod sursa (job #2367387) | Cod sursa (job #8821) | Cod sursa (job #788902)
Cod sursa(job #788902)
#include <fstream>
#include <cmath>
#define inputFile "fact.in"
#define outputFile "fact.out"
#define MAX 100000000
using namespace std;
int p, n;
int countZ( int end){
int res = 0;
int localMax = log2(end)/log2(5);
for(int k=1; k<=localMax; k++){
res += (floor)((long double) end / pow((double) 5, (double) k));
}
return res;
}
int main(){
ifstream in(inputFile);
in>>p ;
int countDigits = 0;
int tmp;
int count = 0;
int start = 0;
int end = MAX;
ofstream output;
output.open(outputFile);
int res;
if(p == 0)
start = 1;
else{
while(start < end){
int mid = (start + end)/2;
res = countZ( mid) ;
if(res >= p)
end = mid;
else
start = mid +1;
}
if(countZ(start) != p)
start = -1;
}
output << start << endl;
output.close();
}