Numbers which are the cube roots of the product of their proper divisors: Difference between revisions
Content deleted Content added
Added a Note about the inclusion of the number 1. |
Thundergnat (talk | contribs) m →{{header|Raku}}: Add a Raku example |
||
Line 18: | Line 18: | ||
OEIS considers 1 to be the first number in this sequence even though, strictly speaking, it has no proper divisors. Please therefore do likewise. |
OEIS considers 1 to be the first number in this sequence even though, strictly speaking, it has no proper divisors. Please therefore do likewise. |
||
<br> |
<br> |
||
=={{header|Raku}}== |
|||
<syntaxhighlight lang="raku" line>use Prime::Factor; |
|||
use Lingua::EN::Numbers; |
|||
my @cube-div = lazy 1, |(2..∞).hyper.grep: { .³ == [×] .&proper-divisors } |
|||
put "First 50 numbers which are the cube roots of the products of their proper divisors:\n" ~ |
|||
@cube-div[^50]».fmt("%3d").batch(10).join: "\n"; |
|||
printf "\n%16s: %s\n", .Int.&ordinal.tc, comma @cube-div[$_ - 1] for 5e2, 5e3, 5e4;</syntaxhighlight> |
|||
{{out}} |
|||
<pre>First 50 numbers which are the cube roots of the products of their proper divisors: |
|||
1 24 30 40 42 54 56 66 70 78 |
|||
88 102 104 105 110 114 128 130 135 136 |
|||
138 152 154 165 170 174 182 184 186 189 |
|||
190 195 222 230 231 232 238 246 248 250 |
|||
255 258 266 273 282 285 286 290 296 297 |
|||
Five hundredth: 2,526 |
|||
Five thousandth: 23,118 |
|||
Fifty thousandth: 223,735</pre> |
|||
=={{header|Wren}}== |
=={{header|Wren}}== |
||
{{libheader|Wren-math}} |
{{libheader|Wren-math}} |
Revision as of 21:55, 29 September 2022
Numbers which are the cube roots of the product of their proper divisors 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.
- Example
Consider the number 24. Its proper divisors are: 1, 2, 3, 4, 6, 8 and 12. Their product is 13,824 and the cube root of this is 24. So 24 satisfies the definition in the task title.
- Task
Compute and show here the first 50 positive integers which are the cube roots of the product of their proper divisors.
Also show the 500th and 5,000th such numbers.
- Stretch
Compute and show the 50,000th such number.
- Reference
- Note
OEIS considers 1 to be the first number in this sequence even though, strictly speaking, it has no proper divisors. Please therefore do likewise.
Raku
use Prime::Factor;
use Lingua::EN::Numbers;
my @cube-div = lazy 1, |(2..∞).hyper.grep: { .³ == [×] .&proper-divisors }
put "First 50 numbers which are the cube roots of the products of their proper divisors:\n" ~
@cube-div[^50]».fmt("%3d").batch(10).join: "\n";
printf "\n%16s: %s\n", .Int.&ordinal.tc, comma @cube-div[$_ - 1] for 5e2, 5e3, 5e4;
- Output:
First 50 numbers which are the cube roots of the products of their proper divisors: 1 24 30 40 42 54 56 66 70 78 88 102 104 105 110 114 128 130 135 136 138 152 154 165 170 174 182 184 186 189 190 195 222 230 231 232 238 246 248 250 255 258 266 273 282 285 286 290 296 297 Five hundredth: 2,526 Five thousandth: 23,118 Fifty thousandth: 223,735
Wren
import "./math" for Int, Nums
import "./fmt" for Fmt
var numbers50 = []
var count = 0
var n = 1
System.print("First 50 numbers which are the cube roots of the products of their proper divisors:")
while (true) {
var pd = Int.properDivisors(n)
if (Nums.prod(pd) == n * n * n) {
count = count + 1
if (count <= 50) {
numbers50.add(n)
if (count == 50) Fmt.tprint("$3d", numbers50, 10)
} else if (count == 500) {
Fmt.print("\n500th : $,d", n)
} else if (count == 5000) {
Fmt.print("5,000th : $,d", n)
} else if (count == 50000) {
Fmt.print("50,000th: $,d", n)
break
}
}
n = n + 1
}
- Output:
First 50 numbers which are the cube roots of the products of their proper divisors: 1 24 30 40 42 54 56 66 70 78 88 102 104 105 110 114 128 130 135 136 138 152 154 165 170 174 182 184 186 189 190 195 222 230 231 232 238 246 248 250 255 258 266 273 282 285 286 290 296 297 500th : 2,526 5,000th : 23,118 50,000th: 223,735