Sphenic numbers

Revision as of 12:59, 17 January 2023 by PureFox (talk | contribs) (Created a new draft task and added a Wren solution.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

A sphenic number is a positive integer that is the product of three distinct prime numbers.

Sphenic numbers is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.
Definitions

For the purposes of this task, a sphenic triplet is a group of three sphenic numbers which are consecutive.

Note that sphenic quadruplets are not possible because very fourth consecutive positive integer is divisible by 4 (= 2 x 2) and its prime factors would not therefore be distinct.

Example

30 (= 2 x 3 x 5) is a sphenic number and is also clearly the first one.

[1309, 1310, 1311] is a sphenic triplet because 1309 (= 7 x 11 x 17), 1310 (= 2 x 5 x 31) and 1311 (= 3 x 19 x 23) are 3 consecutive sphenic numbers.

Task

Calculate and show here:

1. All sphenic numbers less than 1,000.

2. All sphenic triplets less than 10,000.

Stretch

3. How many sphenic numbers are there less than 1 million?

4. How many sphenic triplets are there less than 1 million?

5. What is the 200,000th sphenic number and its 3 prime factors?

6. What is the 5,000th sphenic triplet?

Hint: you only need to consider sphenic numbers less than 1 million to answer 5. and 6.

References


Wren

Library: Wren-math
Library: Wren-seq
Library: Wren-fmt

Simple brute force approach which is quick enough here.

import "./math" for Int
import "./seq" for Lst
import "./fmt" for Fmt

var limit = 1000000
var sphenic = []
System.print("Sphenic numbers less than 1,000:")
for (i in 30...limit) { // can't be less than 2 * 3 * 5 = 30
    var pf = Int.primeFactors(i)
    if (pf.count == 3 && Lst.prune(pf).count == 3) sphenic.add(i)
}
Fmt.tprint("$3d", sphenic.where { |s| s < 1000 }, 15)
System.print("\nSphenic triplets less than 10,000:")
var triplets = []
for (i in 0...sphenic.count-2) {
    var s = sphenic[i]
    if (sphenic[i+1] == s + 1 && sphenic[i+2] == s + 2) {
        triplets.add([s, s + 1, s + 2])
    }
}
Fmt.tprint("$18n", triplets.where { |t| t[2] < 10000 }, 3)
Fmt.print("\nThere are $,d sphenic numbers  less than 1,000,000.", sphenic.count)
Fmt.print("There are $,d sphenic triplets less than 1,000,000.", triplets.count)
var s = sphenic[199999]
Fmt.print("The 200,000th sphenic number is $,d ($s).", s, Int.primeFactors(s).join("*"))
Fmt.print("The 5,000th sphenic triplet is $n.", triplets[4999])
Output:
Sphenic numbers less than 1,000:
 30  42  66  70  78 102 105 110 114 130 138 154 165 170 174 
182 186 190 195 222 230 231 238 246 255 258 266 273 282 285 
286 290 310 318 322 345 354 357 366 370 374 385 399 402 406 
410 418 426 429 430 434 435 438 442 455 465 470 474 483 494 
498 506 518 530 534 555 561 574 582 590 595 598 602 606 609 
610 615 618 627 638 642 645 646 651 654 658 663 665 670 678 
682 705 710 715 730 741 742 754 759 762 777 782 786 790 795 
805 806 814 822 826 830 834 854 861 874 885 890 894 897 902 
903 906 915 935 938 942 946 957 962 969 970 978 986 987 994 

Sphenic triplets less than 10,000:
[1309, 1310, 1311] [1885, 1886, 1887] [2013, 2014, 2015] 
[2665, 2666, 2667] [3729, 3730, 3731] [5133, 5134, 5135] 
[6061, 6062, 6063] [6213, 6214, 6215] [6305, 6306, 6307] 
[6477, 6478, 6479] [6853, 6854, 6855] [6985, 6986, 6987] 
[7257, 7258, 7259] [7953, 7954, 7955] [8393, 8394, 8395] 
[8533, 8534, 8535] [8785, 8786, 8787] [9213, 9214, 9215] 
[9453, 9454, 9455] [9821, 9822, 9823] [9877, 9878, 9879] 

There are 206,964 sphenic numbers  less than 1,000,000.
There are 5,457 sphenic triplets less than 1,000,000.
The 200,000th sphenic number is 966,467 (17*139*409).
The 5,000th sphenic triplet is [918005, 918006, 918007].