A beautiful sequence is an increasing sequence, in which a term Ai divides all Aj, where j>i. Given N find a beautiful sequenec whose last term is N and length of sequenece is maximum possible.
Input: N = 10 Output: 1 5 10 Explanation: 10 is divisible by 1 and 5, 5 is divisible by 1.
Input: N = 3 Output: 1 3 Explanation: 3 is divisible by 1.
You don't need to read or print anything. Your task is to complete the function FindSequenece() which takes N as input parameter and returns a list of beautiful sequence.
Expected Time Complexity: O(nLog(n))
Expected Space Complexity: O(1)
1 <= N <= 105
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?Yes