You are given a positive integer ‘N’. Your task is to find all the positive integers between 1 and ‘N’ (both inclusive) that have exactly 3 divisors. Print these numbers in increasing order.
Note :It is guaranteed that there is at least one such integer under given constraints.
The first line of input contains an integer ‘T’ denoting the number of test cases.
The first and only line of each test case contains a positive integer ‘N’.
Output Format :
For each test case, print a single line consisting of space-separated integers between 1 and ‘n’ (both inclusive) in increasing order that has exactly 3 divisors.
Note :
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 50
4 <= N <= 10^9
Time Limit: 1 sec
2
5
20
4
4 9
Test case 1 :
There are exactly 3 divisors of 4, that is 1, 2, 4.
There is no other integer between 1 and 5 that has exactly three divisors.
Test case 2 :
There are exactly 3 divisors of 4, that is 1, 2, 4.
There are exactly 3 divisors of 9, that is 1, 3, 9.
There is no other integer between 1 and 20 that has exactly three divisors.
2
49
4
4 9 25 49
4
Count divisors of all the integers between 1 and ‘N’.
O(N * sqrt(N)), where ‘N’ is the given positive integer.
It will take sqrt(N) time to count the number of divisors of the given number. We have to count the number of divisors for ‘N’ integers that make its complexity O(N * sqrt(N)).
O(M), where ‘M’ is the number of integers between ‘1’ and ‘N’ having exactly 3 divisors.
Space used by vector ‘result’ will be of the order ‘M’.