Pagini recente » Cod sursa (job #1650865) | Cod sursa (job #3267961) | Cod sursa (job #2398577) | Cod sursa (job #2981873) | Cod sursa (job #1693938)
import java.io.*;
public class MinFactorialNumberWithNZeros {
static int n;
static int ans;
static int getCountOfZeros(int x) {
int count = 0;
while (x > 0) {
x /= 5;
count += x;
}
return count;
}
static int binarySearch(int x) {
int i = -1;
for (int step = 1 << 30; step > 0; step >>= 1)
if ( getCountOfZeros(i + step) < x) {
i += step;
}
return ( i + 1 );
}
public static void main(String[] args) throws IOException{
StreamTokenizer in = new StreamTokenizer(new BufferedReader(new FileReader("fact.in")));
PrintWriter out=new PrintWriter(new BufferedWriter(new FileWriter("fact.out")));
in.nextToken(); n = (int) in.nval;
ans = binarySearch(n);
out.println( (getCountOfZeros(ans) == n)? ans: -1 );
out.close();
}
}