P19782 [GeeksforGeeks] Fact digit sum4125
普及-
题目描述

A(X) for positive integer X is the sum of factorials of its digits. For example, A(154) = 1! + 5! + 4!= 145.
Given a number N, find the minimum number X such that A(X) = N. You have to return a list of digits (without leading zeros) which represent the number X.
Example 1:
Input: N = 40321
Output: 18
Explanation: A(18)=1!+ 8! =40321
Note that A(80) and A(81) are also
40321, But 18 is the smallest
number.
Example 2:
Input: N = 5040
Output: 7
Explanation: A(7) = 7! = 5040.
Your Task:
You don't need to read or print anything. Your task is to complete the function FactDigit() which takes N as input parameter and returns a list of digits which represent the number X.
Expected Time Complexity: O(X) where X ≤ 10^{6}
Expected Space Complexity: O(X)
Constraints:
1 ≤ N ≤ 10^{9}

输入格式

见题面

输出格式

见题面

样例输入
N = 40321
样例输出
18