Jump to content

Numbers which are the cube roots of the product of their proper divisors: Difference between revisions

m
Python example
m (→‎{{header|Raku}}: Add a Raku example)
m (Python example)
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.
<br>
 
 
=={{header|Python}}==
<syntaxhighlight lang=python>''' Rosetta code rosettacode.org/wiki/Numbers_which_are_the_cube_roots_of_the_product_of_their_proper_divisors '''
 
from functools import reduce
from sympy import divisors
 
 
FOUND = 0
for num in range(1, 1_000_000):
divprod = reduce(lambda x, y: x * y, divisors(num)[:-1])if num > 1 else 1
if num * num * num == divprod:
FOUND += 1
if FOUND <= 50:
print(f'{num:5}', end='\n' if FOUND % 10 == 0 else '')
if FOUND == 500:
print(f'\nFive hundreth: {num:,}')
if FOUND == 5000:
print(f'\nFive thousandth: {num:,}')
if FOUND == 50000:
print(f'\nFifty thousandth: {num:,}')
break
</syntaxhighlight>{{out}}
<pre>
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 hundreth: 2,526
 
Five thousandth: 23,118
 
Fifty thousandth: 223,735
</pre>
 
 
=={{header|Raku}}==
<syntaxhighlight lang="raku" line>use Prime::Factor;
4,111

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.