Generation

generate functionFri, 17 Mar 2023

整数 N が与えられます。 N の階乗 N! の末尾に 0 がいくつ付くか求め、出力してください。

import java.util.*; class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int count = 0; int five = 5; while (N % five == 0) { count++; five *= 5; } System.out.println(count); } }

Questions about programming?Chat with your personal AI assistant