Sum of Primes and Non-Primes up to N
EasyP3Coding
Given an integer n, split the numbers 1, 2, ..., n into primes and non-primes. Return [primeSum, nonPrimeSum], the sum of each group.
The number 1 is not prime, so it counts in the non-prime group. For n = 0 both sums are 0.
Example 1
- Input
- n = 10
- Output
- [17,38]
- Why
- Primes 2+3+5+7 = 17; non-primes 1+4+6+8+9+10 = 38.
Example 2
- Input
- n = 1
- Output
- [0,1]
Example 3
- Input
- n = 2
- Output
- [2,1]
Constraints
- 0 <= n <= 10^6
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 10. ⌘Enter runs, ⌘⇧Enter submits.