Cod sursa(job #2722917)

Utilizator ddiana.gamesDiana Games ddiana.games Data 13 martie 2021 13:08:40
Problema Factorial Scor 5
Compilator java Status done
Runda Arhiva de probleme Marime 0.78 kb
import java.io.*;
import java.util.Scanner;

public class Main {
    public static int countZeros(int n) {
        int count = 0;
        while (n > 0) {
            count += n / 5;
            n /= 5;
        }
        return count;
    }

    public static int solution(int p) {
        int pos, step;
        for (pos = -1, step = 1 << 31; step > 0; step >>= 1)
            if (countZeros(pos + step) < p)
                pos += step;
        return pos < 0 ? 1 : pos + 1;
    }

    public static void main(String[] args) throws FileNotFoundException, IOException {
        Scanner in = new Scanner(new FileReader("fact.in"));
        PrintStream out = new PrintStream("fact.out");

        int p = in.nextInt();
        out.print(solution(p));

        in.close();
        out.close();
    }
}