A no is said to be  k-Almost Prime Number if it  has exactly k prime factors (not necessary distinct). Your task is to complete the function printKAlmostPrimes which takes two argument k and N and prints the  first N numbers that are k prime. 
Input:
The first line of input is the no of test cases . Then T test cases follow . Each test case contains two integers k and N .
Output:
For each test case output will be N space separated first N numbers that are k prime numbers.
Constraints:
1<=T<=100
1<=k<=10
1<=N<=50
Example(To be used only for expected output):
Input
1
2 5
Output
4 6 9 10 14
Explanation
In above test case
4 has two prime factors, 2 x 2
6 has two prime factors, 2 x 3
Similarly, 9(3 x 3), 10(2 x 5) and 14(2 x 7)

Source: geeksforgeeks | Difficulty: EASY
Tags: Number theory

Data structures

Starter code: #Your task is to complete this function
#Function should print the required output in one line
#donot print new Line
def printKAlmostPrimes(k, n):
    #Code here

Solutions:
def countPrimeNumber(n):
	count = 0
	while n % 2 == 0:
		n = n / 2
		count += 1
	i = 3
	while i <= n ** 0.5:
		while n % i == 0:
			n /= i
			count += 1
		i += 2
	if n > 2:
		count += 1
	return count

def printKAlmostPrimes(k, n):
	i = 1
	num = 2
	while i <= n:
		if countPrimeNumber(num) == k:
			print(num, end='')
			print(' ', end='')
			i += 1
		num += 1


import math

def primecount(n):
	count = 0
	while n % 2 == 0:
		n = n / 2
		count += 1
	i = 3
	while i <= math.sqrt(n):
		while n % i == 0:
			n = n / i
			count += 1
		i = i + 2
	if n > 2:
		count += 1
	return count

def printKAlmostPrimes(k, n):
	i = 1
	num = 2
	while i <= n:
		if primecount(num) == k:
			print(num, end='')
			print(' ', end='')
			i += 1
		num += 1
	return


def printKAlmostPrimes(k, n):
	a = []
	j = 0
	h = 2
	while j < n:
		m = h
		count = 0
		while m % 2 == 0:
			a.append(2)
			m = m / 2
		for i in range(3, int(m ** (1 / 2)) + 1, 2):
			while m % i == 0:
				a.append(i)
				m = m / i
		if m > 2:
			a.append(m)
		if len(a) == k:
			print(h, end=' ')
			j += 1
		a = []
		h += 1


import math

def primeFactors(n):
	count = 0
	while n % 2 == 0:
		n = n / 2
		count += 1
	i = 3
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			n = n / i
			count += 1
	if n > 2:
		count += 1
	return count

def printKAlmostPrimes(k, n):
	i = 2
	res = []
	while n:
		if primeFactors(i) == k:
			print(i, end=' ')
			n -= 1
		i += 1


def printKAlmostPrimes(k, n):

	def count_prime_factors(num: int) -> int:
		import math
		count = 0
		while num % 2 == 0:
			count += 1
			num //= 2
		for i in range(3, int(math.sqrt(num)) + 1, 2):
			while num % i == 0:
				count += 1
				num //= i
		if num > 1:
			count += 1
		return count
	i = 0
	number = 2
	while i < n:
		if count_prime_factors(number) == k:
			print(number, end=' ')
			i += 1
		number += 1


import math

def prime_factor_count(n):
	count = 0
	while n % 2 == 0:
		n = n / 2
		count += 1
	i = 3
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			n = n / i
			count += 1
	if n > 2:
		count += 1
	return count

def printKAlmostPrimes(k, n):
	i = 1
	no = 2
	ans = []
	while i <= n:
		if prime_factor_count(no) == k:
			print(no, end=' ')
			i += 1
		no += 1


import math

def printKAlmostPrimes(k, n):
	(c, m) = (0, 0)
	for i in range(2, 40000):
		a = i
		for j in range(2, math.floor(math.sqrt(i)) + 1):
			while a % j == 0:
				c += 1
				a //= j
		if a != 1:
			c += 1
		if c == k:
			print(i, end=' ')
			m += 1
		if m == n:
			break
		c = 0


def count(num):
	c = 0
	while num % 2 == 0:
		num = num // 2
		c += 1
	j = 3
	while j * j <= num:
		while num % j == 0:
			num = num // j
			c += 1
		j += 2
	if num > 2:
		c += 1
	return c

def printKAlmostPrimes(k, n):
	i = 1
	num = 2
	while i <= n:
		x = count(num)
		if x == k:
			print(num, end=' ')
			i += 1
		num += 1


import math

def countPrime(n):
	count = 0
	while n % 2 == 0:
		count += 1
		n = n / 2
	for i in range(3, int(n ** 0.5) + 1, 2):
		while n % i == 0:
			count += 1
			n = n / i
	if n > 2:
		count += 1
	return count

def printKAlmostPrimes(k, n):
	num = 2
	while n:
		if countPrime(num) == k:
			print(num, end=' ')
			n -= 1
		num += 1
	return
if __name__ == '__main__':
	t = int(input())
	for i in range(t):
		(k, n) = list(map(int, input().strip().split()))
		printKAlmostPrimes(k, n)
		print('')


def printKAlmostPrimes(k, n):

	def find_prime_factors(n):
		i = 2
		ans = []
		while i * i <= n:
			if n <= 1:
				break
			if n % i == 0:
				ans.append(i)
				n = n // i
			else:
				i += 1
		if n >= 2:
			ans.append(n)
		return ans
	i = 2
	while n > 0:
		factors = find_prime_factors(i)
		if len(factors) == k:
			print(i, end=' ')
			n -= 1
		i += 1


def printKAlmostPrimes(k, n):
	a = []
	l = 2
	while len(a) < n:
		c = 0
		r = l
		for i in range(2, int(l ** 0.5) + 1):
			if r % i == 0:
				while r % i == 0:
					r = r // i
					c += 1
		if r > 1:
			c += 1
		if c == k:
			a.append(l)
		l += 1
	for i in a:
		print(i, end=' ')