You are given two integers N and K. Your task is to print all numbers from 1 to N that have exactly K positive divisors, in ascending order and separated by spaces.
Input: N = 10, K = 2
Output: 2 3 5 7
Explanation: The numbers 2, 3, 5, and 7 are prime numbers, each having exactly two positive divisors: 1 and itself.
Input: N = 20, K = 3
Output: 4 9
Explanation: The positive divisors of 4 are 1, 2, and 4. The positive divisors of 9 are 1, 3, and 9. Both numbers have exactly three positive divisors.
Input: N = 5, K = 1
Output: 1
Explanation: The number 1 has exactly one positive divisor: 1. No other number from 1 to 5 has exactly one positive divisor.
Sign in to write, run, and submit your solution against the full test suite.