Pagini recente » Cod sursa (job #1057461) | Cod sursa (job #3281838) | Autentificare | Cod sursa (job #75008) | Cod sursa (job #3286880)
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.util.Scanner;
public class Main {
public static int countZeros(int v) {
int count = 0;
int p = 5;
while (v / p != 0) {
count += v / p;
p *= 5;
}
return count;
}
public static int binarySearch(int low, int high, int P) {
int res = -1;
while (low <= high) {
int mid = (low + high) >>> 1;
int zeros = countZeros(mid);
if (zeros == P) {
res = mid;
high = mid - 1;
} else if (zeros < P) {
low = mid + 1;
} else {
high = mid -1;
}
}
return res;
}
public static void main(String[] args) throws FileNotFoundException {
try (Scanner scanner = new Scanner(new FileInputStream("fact.in"));
PrintStream pw = new PrintStream(new FileOutputStream("fact.out"))) {
int P = scanner.nextInt();
int res = binarySearch(1, Integer.MAX_VALUE, P);
pw.println(res);
}
}
}