Saturday, 11 February 2012

Codechef -> Practice -> Easy -> Factorial



Solution :


import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

class IOMain {

    private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    public static int readIntLine() throws IOException {
        return Integer.parseInt(br.readLine());
    }

    public static long readLongLine() throws IOException {
        return Long.parseLong(br.readLine());
    }
}

class Factorial {

    public static void main(String[] args) throws IOException {
        int i = IOMain.readIntLine();
        while (i-- > 0) {
            int num = IOMain.readIntLine();
            int power = 1;
            int count = 0;
            int x = 0;
            while ((x = (Double.valueOf(Math.pow(5, power)).intValue())) <= num) {
                count += (num / (x));
                power++;
            }
            System.out.println(count);
        }
    }
}

No comments:

Post a Comment