Perfect numbers: Difference between revisions
Content added Content deleted
(→{{header|Picat}}: Split into subsections, fixed link) |
|||
Line 2,900: | Line 2,900: | ||
=={{header|Picat}}== |
=={{header|Picat}}== |
||
===Simple divisors/1 function=== |
|||
First is the slow <code>perfect1/1</code> that use the simple divisors/1 function: |
|||
<lang Picat>go => |
<lang Picat>go => |
||
println(perfect1=[I : I in 1..10_000, perfect1(I)]), |
println(perfect1=[I : I in 1..10_000, perfect1(I)]), |
||
Line 2,911: | Line 2,912: | ||
<pre>perfect1 = [1,6,28,496,8128]</pre> |
<pre>perfect1 = [1,6,28,496,8128]</pre> |
||
===Using formula for perfect number candidates=== |
|||
⚫ | |||
⚫ | |||
<lang Picat>go2 => |
<lang Picat>go2 => |
||
println("Using the formula: 2^(p-1)*(2^p-1) for prime p"), |
println("Using the formula: 2^(p-1)*(2^p-1) for prime p"), |
||
Line 2,967: | Line 2,967: | ||
CPU time 118.039 seconds. Backtracks: 0</pre> |
CPU time 118.039 seconds. Backtracks: 0</pre> |
||
===Using list of the prime generating the perfect numbers=== |
|||
Now let's cheat a little. At |
Now let's cheat a little. At https://en.wikipedia.org/wiki/Perfect_number there is a list of the first 48 primes that generates perfect numbers according to the formula 2^(p-1)*(2^p-1) for prime p. |
||
The perfect numbers are printed only if they has < 80 digits, otherwise the number of digits are shown. The program stops when reaching a number with more than 100 000 digits. (Note: The major time running this program is getting the number of digits.) |
The perfect numbers are printed only if they has < 80 digits, otherwise the number of digits are shown. The program stops when reaching a number with more than 100 000 digits. (Note: The major time running this program is getting the number of digits.) |
||
<lang Picat>go3 => |
<lang Picat>go3 => |
||
ValidP = [2, 3, 5, 7, 13, 17, 19, 31, 61, 89, 107, 127, 521, 607, |
ValidP = [2, 3, 5, 7, 13, 17, 19, 31, 61, 89, 107, 127, 521, 607, |
||
Line 3,026: | Line 3,026: | ||
prime 132049: len = 79502 |
prime 132049: len = 79502 |
||
prime 216091: len = 130100</pre> |
prime 216091: len = 130100</pre> |
||
=={{header|PicoLisp}}== |
=={{header|PicoLisp}}== |