Skip to the code
cf.
+10 XP

#637 Prime Raffle Tickets

easy

A company raffle page only hands out ticket numbers that are prime. Tickets are numbered from 1 to n.

Write primeTickets(n) that returns every prime number from 2 to n, in ascending order. Return [] if there are none.

Example 1

Input: n = 10
Output: [2,3,5,7]

The primes up to 10. 9 = 3 × 3 and the even numbers above 2 are crossed out.

Example 2

Input: n = 1
Output: []

1 is not prime, so there are no tickets.

Constraints

  • 0 <= n <= 10^6
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).