题目描述
For a given non-negative integer N, find the next smallest Happy Number. A number is called happy if it leads to 1 after a sequence of steps. Wherein at each step the number is replaced by the sum of squares of its digits that is if we start with Happy Number and keep replacing it with sum of squares of its digits, we reach 1 at some point.
Example 1:
Input:
N = 8
Output:
10
Explanation:
Next happy number after 8 is 10 since
11 + 00 = 1
Example 2:
Input:
N = 10
Output
13
Explanation:
After 10, 13 is the smallest happy number because
11 + 33 = 10, so we replace 13 by 10 and 11 + 00 = 1.
Your Task:
You don't need to read input or print anything. Your task is to complete the function nextHappy() which takes an integer N as input parameters and returns an integer, next Happy number after N.
Expected Time Complexity: O(Nlog_{10}N)
Expected Space Complexity: O(1)
Constraints:
1<=N<=10^{5}
输入格式
见题面
输出格式
见题面