题目描述
Given a number n, find the last non-zero digit in n!.
Examples:
Input : n = 5
Output : 2
5! = 5 * 4 * 3 * 2 * 1 = 120
Last non-zero digit in 120 is 2.
Input : n = 33
Output : 8
Your Task:
You don't need to read input or print anything. Your task is to complete the function lastNon0Digit() which takes the integer N as input parameters and returns the last non-zero digit in n!.
Expected Time Complexity: O(N^2)
Expected Auxiliary Space: O(1)
Constraints:
1 ≤ N ≤ 100
输入格式
见题面
输出格式
见题面
样例输入
n = 5
样例输出
2
5! = 5 * 4 * 3 * 2 * 1 = 120
Last non-zero digit in 120 is 2.