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 A AS (
SELECT LEVEL AS L FROM DUAL CONNECT BY LEVEL <= 1000
)
SELECT
LISTAGG(L,'&') WITHIN GROUP (ORDER BY L)
FROM
(
SELECT L FROM A MAIN
WHERE
NOT EXISTS
(
SELECT 1 FROM A SUB
WHERE
MAIN.L>SUB.L
AND MOD(MAIN.L,L)=0
AND SUB.L>1
)
AND L<>1
);
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 A AS ( SELECT LEVEL AS L FROM DUAL CONNECT BY LEVEL <= 1000 ) SELECT LISTAGG(L,'&') WITHIN GROUP (ORDER BY L) FROM ( SELECT L FROM A MAIN WHERE NOT EXISTS ( SELECT 1 FROM A SUB WHERE MAIN.L>SUB.L AND MOD(MAIN.L,L)=0 AND SUB.L>1 ) AND L<>1 );