We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
WITH RECURSIVE numbers AS(
SELECT 2 AS num
UNION ALL
SELECT num + 1
FROM numbers
WHERE num < 1000
),
Prime AS (
SELECT num
FROM numbers n
WHERE NOT EXISTS(
SELECT 1
FROM numbers n1
WHERE n.num % d.n1.num = 0
AND n.num != n1.num
)
)
SELECT GROUP_CONCAT(num SEPARATOR '&') AS pnumbers
FROM Prime;
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Print Prime Numbers
You are viewing a single comment's thread. Return to all comments →
WITH RECURSIVE numbers AS( SELECT 2 AS num UNION ALL SELECT num + 1 FROM numbers WHERE num < 1000 ), Prime AS ( SELECT num FROM numbers n WHERE NOT EXISTS( SELECT 1 FROM numbers n1 WHERE n.num % d.n1.num = 0 AND n.num != n1.num ) )
SELECT GROUP_CONCAT(num SEPARATOR '&') AS pnumbers FROM Prime;