Given an integer ‘N’, your task is to write a program that returns all the divisors of ‘N’ in ascending order.
'N' = 5.
The divisors of 5 are 1, 5.
The input consists of a single line containing an integer, ‘N’.
Output Format :
The output should be a single line containing the divisors of ‘N’, separated by spaces, in ascending order.
10
1 2 5 10
The divisors of 10 are 1,2,5,10.
6
1 2 3 6
The divisors of 6 are 1, 2, 3, and 6.
1 <= 'N' <= 10^5
What remainder signifies divisibility by a number.
Iterate through all the numbers from 1 to 'N', and check if that number divides ‘N’, and if it divides, print it.
O(N), where ‘N’ is the given number.
We are traversing from 1 to ‘N’, So the space complexity is O(N).
O(1).
We use constant extra space, So the space complexity is O(1).