Fortunate numbers: Difference between revisions
(Added new draft task and Wren example.) |
m (Minor change to task description.) |
||
Line 10: | Line 10: | ||
;Task |
;Task |
||
After sorting and removal of any duplicates, show on this page the first '''8''' Fortunate numbers or, if your language supports ''big integers'', the first '''50''' Fortunate numbers. |
After sorting and removal of any duplicates, compute and show on this page the first '''8''' Fortunate numbers or, if your language supports ''big integers'', the first '''50''' Fortunate numbers. |
||
Revision as of 11:38, 1 August 2021
- Definition
A Fortunate number is the smallest integer m > 1 such that for a given positive integer n, primorial(n) + m is a prime number, where primorial(n) is the product of the first n prime numbers.
For example the first fortunate number is 3 because primorial(1) is 2 and 2 + 3 = 5 which is prime whereas 2 + 2 = 4 is composite.
- Task
After sorting and removal of any duplicates, compute and show on this page the first 8 Fortunate numbers or, if your language supports big integers, the first 50 Fortunate numbers.
- Related task
- See also
- oeis:A005235 Fortunate numbers
- oeis:A046066 Fortunate numbers, sorted with duplicates removed
Wren
<lang ecmascript>import "/math" for Int import "/big" for BigInt import "/sort" for Sort import "/seq" for Lst import "/fmt" for Fmt
var primes = Int.primeSieve(379) var primorial = BigInt.one var fortunates = [] for (prime in primes) {
primorial = primorial * prime var j = 3 while (true) { if ((primorial + j).isProbablePrime(5)) { fortunates.add(j) break } j = j + 2 }
} fortunates = Lst.distinct(fortunates) Sort.quick(fortunates) System.print("After sorting, the first 50 distinct fortunate numbers are:") for (chunk in Lst.chunks(fortunates[0..49], 10)) Fmt.print("$3d", chunk)</lang>
- Output:
After sorting, the first 50 distinct fortunate numbers are: 3 5 7 13 17 19 23 37 47 59 61 67 71 79 89 101 103 107 109 127 151 157 163 167 191 197 199 223 229 233 239 271 277 283 293 307 311 313 331 353 373 379 383 397 401 409 419 421 439 443