Pagini recente » Cod sursa (job #1979593) | Cod sursa (job #2411622) | Cod sursa (job #1275785) | Cod sursa (job #531721) | Cod sursa (job #1693900)
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.StreamTokenizer;
public class MinFactorialNumberWithNZeros {
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")));
StreamTokenizer out = new StreamTokenizer(new BufferedReader(new FileReader("fact.out")));
int n;
in.nextToken(); n = (int) in.nval;
int ans = binarySearch(n);
System.out.println( (getCountOfZeros(ans) == n)? ans: -1 );
}
}