Jump to content

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

m
→‎{{header|Phix}}: ugh, fast/safe comment backwards, added precision error comment.
m (→‎{{header|Phix}}: missing ))
m (→‎{{header|Phix}}: ugh, fast/safe comment backwards, added precision error comment.)
Line 143:
<span style="color: #008080;">while</span> <span style="color: #000000;">count</span><span style="color: #0000FF;"><</span><span style="color: #000000;">500000</span> <span style="color: #008080;">do</span>
<span style="color: #000080;font-style:italic;">-- if product(factors(n))=n*n*n then</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">or</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">factors</span><span style="color: #0000FF;">(</span><span style="color: #000000;">n</span><span style="color: #0000FF;">))=</span><span style="color: #000000;">6</span> <span style="color: #008080;">then</span> <span style="color: #000080;font-style:italic;">-- fastersafer/smidge saferfaster</span>
<span style="color: #000000;">count</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">count</span><span style="color: #0000FF;"><=</span><span style="color: #000000;">50</span> <span style="color: #008080;">then</span>
Line 158:
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<!--</syntaxhighlight>-->
By default factors() does not include 1 and n, or I could use length(factors(n,1))=8. 25% faster than using product()., which
exceeds precision limits on 32-bit for n=180, and on 64bit for n=240, though since you'll get exactly the same precision error on the n*n*n it kinda "worked by chance".
{{out}}
<pre>
7,820

edits

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