23
2
A prime power is a positive integer n that can be written in the form n = pk where p is a prime and k is a positive integer. For example, some prime powers are [2, 3, 5, 4, 9, 25, 8, 27, 125]
.
Next, consider prime powers of 2. These are [2, 4, 8, 16, ...]
and can be written in the form 2k. They would all be included when considering prime powers beneath 20. However, 16 is the maximal prime power with a base prime of 2 in that range. A prime power pk is maximal in a range if it is the highest power of p in that range. We are only interested in the maximal prime power in each range so all lower prime powers must be excluded.
Your goal is to write a function or program that takes a positive integer n and outputs the maximal prime powers in the range [2, 3, 4, ..., n]
.
Thanks to @Peter Taylor for clarifying the definition of maximal prime power and more.
Rules
- This is code-golf so make your code as short as possible.
- The maximal prime powers may be output in any order but there must be no duplicates.
Test cases
n result
1 []
2 [2]
3 [2, 3]
4 [3, 4]
5 [3, 4, 5]
6 [3, 4, 5]
7 [3, 4, 5, 7]
20 [5, 7, 9, 11, 13, 16, 17, 19]
50 [11, 13, 17, 19, 23, 25, 27, 29, 31, 32, 37, 41, 43, 47, 49]
100 [11, 13, 17, 19, 23, 25, 29, 31, 37, 41, 43, 47, 49, 53, 59, 61, 64, 67, 71, 73, 79, 81, 83, 89, 97]
10000 <1229 results>
[101, 103, 107, 109, 113, 127, 131, 137, 139, 149, ..., 9887, 9901, 9907, 9923, 9929, 9931, 9941, 9949, 9967, 9973]
The full list of maximal prime powers for 10000 can be found here.
Oh so obvious once one sees it! – Jonathan Allan – 2017-02-07T00:48:31.563
15
Power floor
What the heck – JungHwan Min – 2017-02-07T06:22:16.5171This post officially convinced me to learn Jelly. – Chandler Watson – 2017-02-07T06:44:28.707