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.
SET SESSION group_concat_max_len = 1000000;
WITH RECURSIVE numbers AS (
SELECT 2 AS n
UNION ALL
SELECT n + 1 FROM numbers WHERE n + 1 <= 1000
)
SELECT GROUP_CONCAT(n SEPARATOR '&') AS prime_numbers
FROM numbers
WHERE NOT EXISTS (
SELECT 1
FROM numbers AS d
WHERE d.n < n AND d.n > 1 AND MOD(n, d.n) = 0
);
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 →
Why this is faling but output is correct
SET SESSION group_concat_max_len = 1000000; WITH RECURSIVE numbers AS ( SELECT 2 AS n UNION ALL SELECT n + 1 FROM numbers WHERE n + 1 <= 1000 ) SELECT GROUP_CONCAT(n SEPARATOR '&') AS prime_numbers FROM numbers WHERE NOT EXISTS ( SELECT 1 FROM numbers AS d WHERE d.n < n AND d.n > 1 AND MOD(n, d.n) = 0 );