From 5cb227272124af3455a5e23ab300b18745833374 Mon Sep 17 00:00:00 2001 From: hacreating <68935517+hacreating@users.noreply.github.com> Date: Mon, 31 Oct 2022 02:10:30 +0530 Subject: [PATCH] Create Alpha.java Most of the students know how to write a program to find a trailing zero , but when there is a twist come in a question or problem statement like find the trailing zeros in factorial of the number enter by the user or input then everyone got confused how to do this , here I have an super optimized approach to such problem . example input :- 5 (5! =120) , output :- 1 example input :- 25 , output :- 6 example input :- 200 , output :- 49 --- Leetcode/Alpha.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Leetcode/Alpha.java diff --git a/Leetcode/Alpha.java b/Leetcode/Alpha.java new file mode 100644 index 0000000..d1080f3 --- /dev/null +++ b/Leetcode/Alpha.java @@ -0,0 +1,17 @@ +import java.util.Scanner; +class Alpha{ + static int trailingZeros(int n){ + int res = 0; + int powOf5 =5; + while(n>=powOf5){ + res = res+ (n/powOf5); + powOf5 = powOf5*5; + } + return res; + } + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int n =sc.nextInt(); + System.out.println(trailingZeros(n)); + } +}