35
3
Most of us know...
that all primes p>3
are of the form
But, how many are the Plus Primes (6n+1
) and how many are the Minus Primes (6n-1
) in a certain range?
The Challenge
Given an integer k>5
, count how many primes<=k
are PlusPrimes and how many are MinusPrimes.
Examples
for k=100
we have
[5, 11, 17, 23, 29, 41, 47, 53, 59, 71, 83, 89]
12 MinusPrimes
and
[7, 13, 19, 31, 37, 43, 61, 67, 73, 79, 97]
11 PlusPrimes
for k=149
we have
[5, 11, 17, 23, 29, 41, 47, 53, 59, 71, 83, 89, 101, 107, 113, 131, 137, 149]
18 MinusPrimes
and
[7, 13, 19, 31, 37, 43, 61, 67, 73, 79, 97, 103, 109, 127, 139]
15 PlusPrimes
Rules
Your code must output 2 integers: one for the MinusPrimes and one for the PlusPrimes in any order you like (please specify which is which).
This is code-golf: shortest answer in bytes wins!
Test Cases
Input -> Output [MinusPrimes,PlusPrimes]
6->[1,0]
7->[1,1]
86->[11,10]
986->[86,78]
5252->[351,344]
100000->[4806,4784]
4000000->[141696, 141448]
45I did not know! :( – Stewie Griffin – 2017-08-29T15:14:30.267
13@StewieGriffin, it's easy to intuit if you look at the modulus sequence:
0%6
is a multiple of 6,1%6
cannot be determined,2%6
is a multiple of 2,3%6
is a multiple of 3,4%6
is a multiple of 2, and5%6
cannot be determined. – zzzzBov – 2017-08-29T23:17:37.4173@zzzzBov that'd be really helpful if I knew why modulus had a sequence, and what it meant for primes... I wish high school taught number theory... – Socratic Phoenix – 2017-08-30T03:43:08.947
@SocraticPhoenix, modulus means "remainder after division". 0, 6, 12, etc all produce 0 after division by 6; 1, 7, 13 all produce 1. Since we're looking for numbers that can't be divided into factors, knowing that a number is divisible by an integer greater than 1 tells us that the number is not prime. – zzzzBov – 2017-08-30T04:33:09.277