Cod sursa(job #1376043)

Utilizator thaghostAndrei Dulceanu thaghost Data 5 martie 2015 15:39:01
Problema Factorial Scor 20
Compilator java Status done
Runda Arhiva de probleme Marime 0.69 kb
import java.io.FileInputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws IOException {
		Scanner in = new Scanner(new FileInputStream("fact.in"));
		PrintWriter out = new PrintWriter("fact.out");

		int n = in.nextInt();
		in.close();

		int zeros = 0;
		long number = 0;

		while (zeros < n) {
			number += 5;

			long temp = number;
			while (temp % 5 == 0) {
				temp /= 5;
				zeros++;
			}
		}

		if (zeros == 0) {
			out.println(1);
		} else {
			if (zeros == n) {
				out.println(number);
			} else {
				out.println(-1);
			}
		}
		
		out.close();
	}
}