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 CTE_B AS (SELECT 2 AS START_NUM FROM DUAL )
, CTE_R(MOD_NUM) AS (
SELECT START_NUM AS MOD_NUM FROM CTE_B
UNION ALL SELECT MOD_NUM + 1 FROM CTE_R WHERE MOD_NUM <=1000
)
SELECT LISTAGG(n.mod_num,'&') WITHIN GROUP (ORDER BY n.mod_num) FROM CTE_R n
where not exists(select 1 from CTE_R d
where d.mod_num < n.mod_num and d.mod_num > 1 and mod(n.mod_num ,d.mod_num) =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 →
WITH CTE_B AS (SELECT 2 AS START_NUM FROM DUAL ) , CTE_R(MOD_NUM) AS ( SELECT START_NUM AS MOD_NUM FROM CTE_B UNION ALL SELECT MOD_NUM + 1 FROM CTE_R WHERE MOD_NUM <=1000 ) SELECT LISTAGG(n.mod_num,'&') WITHIN GROUP (ORDER BY n.mod_num) FROM CTE_R n where not exists(select 1 from CTE_R d where d.mod_num < n.mod_num and d.mod_num > 1 and mod(n.mod_num ,d.mod_num) =0)