Zumkeller numbers: Difference between revisions

m
(→‎{{header|Pascal}}: New pre checked gets 95% .Odd til 140,000,000 287073 95.985 % 133.663 s instead of 3933.063 s)
 
(31 intermediate revisions by 17 users not shown)
Line 1:
{{task|Prime Numbers}}
Zumkeller numbers are the set of numbers whose divisors can be partitioned into two disjoint sets that sum to the same value. Each sum must contain divisor values that are not in the other sum, and all of the divisors must be in one or the other. There are no restrictions on ''how'' the divisors are partitioned, only that the two partition sums are equal.
 
Line 33:
:* '''[[Abundant, deficient and perfect number classifications]]'''
:* '''[[Proper divisors]]''' , '''[[Factors of an integer]]'''
 
=={{header|11l}}==
{{trans|D}}
 
<syntaxhighlight lang="11l">F getDivisors(n)
V divs = [1, n]
V i = 2
L i * i <= n
I n % i == 0
divs [+]= i
 
V j = n I/ i
I i != j
divs [+]= j
i++
R divs
 
F isPartSum(divs, sum)
I sum == 0
R 1B
 
V le = divs.len
I le == 0
R 0B
 
V last = divs.last
[Int] newDivs
L(i) 0 .< le - 1
newDivs [+]= divs[i]
 
I last > sum
R isPartSum(newDivs, sum)
E
R isPartSum(newDivs, sum) | isPartSum(newDivs, sum - last)
 
F isZumkeller(n)
V divs = getDivisors(n)
V s = sum(divs)
 
I s % 2 == 1
R 0B
 
I n % 2 == 1
V abundance = s - 2 * n
R abundance > 0 & abundance % 2 == 0
 
R isPartSum(divs, s I/ 2)
 
print(‘The first 220 Zumkeller numbers are:’)
V i = 2
V count = 0
L count < 220
I isZumkeller(i)
print(‘#3 ’.format(i), end' ‘’)
count++
I count % 20 == 0
print()
i++
 
print("\nThe first 40 odd Zumkeller numbers are:")
i = 3
count = 0
L count < 40
I isZumkeller(i)
print(‘#5 ’.format(i), end' ‘’)
count++
I count % 10 == 0
print()
i += 2
 
print("\nThe first 40 odd Zumkeller numbers which don't end in 5 are:")
i = 3
count = 0
L count < 40
I i % 10 != 5 & isZumkeller(i)
print(‘#7 ’.format(i), end' ‘’)
count++
I count % 8 == 0
print()
i += 2</syntaxhighlight>
 
{{out}}
<pre>
The first 220 Zumkeller numbers are:
6 12 20 24 28 30 40 42 48 54 56 60 66 70 78 80 84 88 90 96
102 104 108 112 114 120 126 132 138 140 150 156 160 168 174 176 180 186 192 198
204 208 210 216 220 222 224 228 234 240 246 252 258 260 264 270 272 276 280 282
294 300 304 306 308 312 318 320 330 336 340 342 348 350 352 354 360 364 366 368
372 378 380 384 390 396 402 408 414 416 420 426 432 438 440 444 448 456 460 462
464 468 474 476 480 486 490 492 496 498 500 504 510 516 520 522 528 532 534 540
544 546 550 552 558 560 564 570 572 580 582 588 594 600 606 608 612 616 618 620
624 630 636 640 642 644 650 654 660 666 672 678 680 684 690 696 700 702 704 708
714 720 726 728 732 736 740 744 750 756 760 762 768 770 780 786 792 798 804 810
812 816 820 822 828 832 834 836 840 852 858 860 864 868 870 876 880 888 894 896
906 910 912 918 920 924 928 930 936 940 942 945 948 952 960 966 972 978 980 984
 
The first 40 odd Zumkeller numbers are:
945 1575 2205 2835 3465 4095 4725 5355 5775 5985
6435 6615 6825 7245 7425 7875 8085 8415 8505 8925
9135 9555 9765 10395 11655 12285 12705 12915 13545 14175
14805 15015 15435 16065 16695 17325 17955 18585 19215 19305
 
The first 40 odd Zumkeller numbers which don't end in 5 are:
81081 153153 171171 189189 207207 223839 243243 261261
279279 297297 351351 459459 513513 567567 621621 671517
729729 742203 783783 793611 812889 837837 891891 908523
960687 999999 1024947 1054053 1072071 1073709 1095633 1108107
1145529 1162161 1198197 1224531 1270269 1307691 1324323 1378377
</pre>
 
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
<langsyntaxhighlight lang="AArch64 Assembly">
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program zumkellex641.s */
Line 524 ⟶ 633:
/* for this file see task include a file in language AArch64 assembly */
.include "../includeARM64.inc"
</syntaxhighlight>
</lang>
{{Output:}}
<pre>
Line 550 ⟶ 659:
 
=={{header|AppleScript}}==
On my machine, this takes about 0.28 seconds to perform the two main searches and a further 107 to do the stretch task. However, the latter time can be dramatically reduced to 1.7 seconds with the cheat of knowing beforehand that the first 200 or so odd Zumkellers not ending with 5 are divisible by 63. The "abundant number" optimisation's now used with odd numbers, but the cheat-free running time was only two to three seconds longer without it.
This takes about 0.38 seconds to execute the two main searches — then a further 109 for the stretch goal!
 
<syntaxhighlight lang="applescript">-- Sum n's proper divisors.
on aliquotSum(n)
if (n < 2) then return 0
set sum to 1
set sqrt to n ^ 0.5
set limit to sqrt div 1
if (limit = sqrt) then
set sum to sum + limit
set limit to limit - 1
end if
repeat with i from 2 to limit
if (n mod i is 0) then set sum to sum + i + n div i
end repeat
return sum
end aliquotSum
 
-- Return n's proper divisors.
<lang applescript>on properDivisors(n)
on properDivisors(n)
set output to {}
Line 574 ⟶ 701:
end properDivisors
 
-- Does a subset of the given list of numbers add up to the target value?
on canSumTo(lst, target)
on subsetOf:numberList sumsTo:target
script o
property llst : lstnumberList
property someNegatives : false
on cstssp(target, i)
repeat while (i > 1)
set n to item i of my llst
if (n = target) then return true
if (i = 1) then return false
set i to i - 1
if ((n = target) or (((n < target) or (someNegatives)) and (cstssp(target - n, i)))) then return true
end repeat
return (target = beginning of my lst)
end cs
end ssp
end script
-- The search can be more efficient if it's known the list contains no negatives.
repeat with n in o's lst
if (n < 0) then
set o's someNegatives to true
exit repeat
end if
end repeat
return o's cstssp(target, count o's llst)
end subsetOf:sumsTo:
end canSumTo
 
-- Is n a Zumkeller number?
on isZumkeller(n)
-- Yes if its aliquot sum is greater than or equal to it, the difference between them is even, and
script o
-- either n is odd or a subset of its proper divisors sums to half the sum of the divisors and it.
property divisors : properDivisors(n)
-- Using aliquotSum() to get the divisor sum and then calling properDivisors() too if a list's actually
end script
-- needed is generally faster than using properDivisors() in the first place and summing the result.
set sum to aliquotSum(n)
return ((sum ≥ n) and ((sum - n) mod 2 = 0) and ¬
repeat with thisDivisor in o's divisors
((n mod 2 = 1) or (my subsetOf:(properDivisors(n)) sumsTo:((sum + n) div 2))))
set sum to sum + thisDivisor
end repeat
set halfSum to sum / 2
return ((halfSum ≥ n) and (halfSum as integer = halfSum) and (canSumTo(o's divisors, halfSum)))
end isZumkeller
 
-- Task code:
-- Find and return q Zumkeller numbers, starting the search at n and continuing at the
on zumkellerNumbers(target, n, interval, filter)
-- Params:given how many requiredinterval, firstapplying numberthe toZumkeller test, intervalonly betweento numbers tested,passing the given filter.
on zumkellerNumbers(q, n, interval, filter)
-- script object imposing any further restrictions on the numbers.
script o
property zumkellers : {}
Line 615 ⟶ 747:
set counter to 0
repeat until (counter = targetq)
if ((filter's OK(n)) and (isZumkeller(n))) then
set end of o's zumkellers to n
Line 626 ⟶ 758:
end zumkellerNumbers
 
on joinText(textList, delimiter)
on format(resultList, heading, resultsPerLine, separator)
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to delimiter
set txt to textList as text
set AppleScript's text item delimiters to astid
return txt
end joinText
 
on formatForDisplay(resultList, heading, resultsPerLine, separator)
script o
property input : resultList
Line 632 ⟶ 773:
end script
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to separator
set len to (count o's input)
repeat with i from 1 to len by resultsPerLine
set j to i + resultsPerLine - 1
if (j > len) then set j to len
set end of o's output to joinText(items i thru j of o's input, separator) as text
end repeat
set AppleScript's text item delimiters to linefeed
set output toreturn joinText(o's output, as textlinefeed)
end formatForDisplay
set AppleScript's text item delimiters to astid
return output
end format
 
on doTask(cheating)
set output to {}
script defaultnoFilter
on OK(n)
return true
Line 654 ⟶ 791:
end script
set header to "1st 220 Zumkeller numbers:"
set end of output to formatformatForDisplay(zumkellerNumbers(220, 1, 1, defaultnoFilter), header, 20, " ")
set header to "1st 40 odd Zumkeller numbers:"
set end of output to formatformatForDisplay(zumkellerNumbers(40, 1, 2, defaultnoFilter), header, 10, " ")
-- Stretch goal:
set header to "1st 40 odd Zumkeller numbers not ending with 5:"
script notDivisibleBy5no5Multiples
on OK(n)
return (n mod 5 > 0)
end OK
end script
if (cheating) then
set end of output to format(zumkellerNumbers(40, 1, 2, notDivisibleBy5), header, 10, " ")
-- Knowing that the HCF of the first 203 odd Zumkellers not ending with 5
set astid to AppleScript's text item delimiters
-- is 63, just check 63 and each 126th number thereafter.
set AppleScript's text item delimiters to linefeed & linefeed
-- For the 204th - 907th such numbers, the HCF reduces to 21, so adjust accordingly.
set output to output as text
-- (See Horsth's comments on the Talk page.)
set AppleScript's text item delimiters to astid
set zumkellers to zumkellerNumbers(40, 63, 126, no5Multiples)
return output
else
-- Otherwise check alternate numbers from 1.
set zumkellers to zumkellerNumbers(40, 1, 2, no5Multiples)
end if
set end of output to formatForDisplay(zumkellers, header, 10, " ")
return joinText(output, linefeed & linefeed)
end doTask
 
local cheating
doTask()</lang>
set cheating to false
doTask(cheating)</syntaxhighlight>
 
{{output}}
<langsyntaxhighlight lang="applescript">"1st 220 Zumkeller numbers:
6 12 20 24 28 30 40 42 48 54 56 60 66 70 78 80 84 88 90 96
102 104 108 112 114 120 126 132 138 140 150 156 160 168 174 176 180 186 192 198
Line 697 ⟶ 845:
351351 459459 513513 567567 621621 671517 729729 742203 783783 793611
812889 837837 891891 908523 960687 999999 1024947 1054053 1072071 1073709
1095633 1108107 1145529 1162161 1198197 1224531 1270269 1307691 1324323 1378377"</langsyntaxhighlight>
 
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi}}
<langsyntaxhighlight lang="ARM Assembly">
/* ARM assembly Raspberry PI */
/* program zumkeller4.s */
Line 1,379 ⟶ 1,527:
/***************************************************/
.include "../affichage.inc"
</syntaxhighlight>
</lang>
<pre>
Program start
Line 1,412 ⟶ 1,560:
=={{header|C sharp|C#}}==
{{trans|Go}}
<langsyntaxhighlight lang="csharp">using System;
using System.Collections.Generic;
using System.Linq;
Line 1,507 ⟶ 1,655:
}
}
}</langsyntaxhighlight>
{{out}}
<pre>The first 220 Zumkeller numbers are:
Line 1,536 ⟶ 1,684:
 
=={{header|C++}}==
<langsyntaxhighlight lang="cpp>#include <iostream">
#include <cmath>
#include <vector>
Line 1,678 ⟶ 1,826:
// if we get here it ain't no zum
return false;
}</langsyntaxhighlight>
{{out}}
<pre>
Line 1,723 ⟶ 1,871:
=={{header|D}}==
{{trans|C#}}
<langsyntaxhighlight lang="d">import std.algorithm;
import std.stdio;
 
Line 1,813 ⟶ 1,961:
}
}
}</langsyntaxhighlight>
{{out}}
<pre>The first 220 Zumkeller numbers are:
Line 1,840 ⟶ 1,988:
960687 999999 1024947 1054053 1072071 1073709 1095633 1108107
1145529 1162161 1198197 1224531 1270269 1307691 1324323 1378377</pre>
 
=={{header|EasyLang}}==
<syntaxhighlight>
proc divisors n . divs[] .
divs[] = [ 1 n ]
for i = 2 to sqrt n
if n mod i = 0
j = n / i
divs[] &= i
if i <> j
divs[] &= j
.
.
.
.
func ispartsum divs[] sum .
if sum = 0
return 1
.
if len divs[] = 0
return 0
.
last = divs[len divs[]]
len divs[] -1
if last > sum
return ispartsum divs[] sum
.
if ispartsum divs[] sum = 1
return 1
.
return ispartsum divs[] (sum - last)
.
func iszumkeller n .
divisors n divs[]
for v in divs[]
sum += v
.
if sum mod 2 = 1
return 0
.
if n mod 2 = 1
abund = sum - 2 * n
return if abund > 0 and abund mod 2 = 0
.
return ispartsum divs[] (sum / 2)
.
#
print "The first 220 Zumkeller numbers are:"
i = 2
repeat
if iszumkeller i = 1
write i & " "
count += 1
.
until count = 220
i += 1
.
print "\n\nThe first 40 odd Zumkeller numbers are:"
count = 0
i = 3
repeat
if iszumkeller i = 1
write i & " "
count += 1
.
until count = 40
i += 2
.
</syntaxhighlight>
 
{{out}}
<pre>
The first 220 Zumkeller numbers are:
6 12 20 24 28 30 40 42 48 54 56 60 66 70 78 80 84 88 90 96 102 104 108 112 114 120 126 132 138 140 150 156 160 168 174 176 180 186 192 198 204 208 210 216 220 222 224 228 234 240 246 252 258 260 264 270 272 276 280 282 294 300 304 306 308 312 318 320 330 336 340 342 348 350 352 354 360 364 366 368 372 378 380 384 390 396 402 408 414 416 420 426 432 438 440 444 448 456 460 462 464 468 474 476 480 486 490 492 496 498 500 504 510 516 520 522 528 532 534 540 544 546 550 552 558 560 564 570 572 580 582 588 594 600 606 608 612 616 618 620 624 630 636 640 642 644 650 654 660 666 672 678 680 684 690 696 700 702 704 708 714 720 726 728 732 736 740 744 750 756 760 762 768 770 780 786 792 798 804 810 812 816 820 822 828 832 834 836 840 852 858 860 864 868 870 876 880 888 894 896 906 910 912 918 920 924 928 930 936 940 942 945 948 952 960 966 972 978 980 984
 
The first 40 odd Zumkeller numbers are:
945 1575 2205 2835 3465 4095 4725 5355 5775 5985 6435 6615 6825 7245 7425 7875 8085 8415 8505 8925 9135 9555 9765 10395 11655 12285 12705 12915 13545 14175 14805 15015 15435 16065 16695 17325 17955 18585 19215 19305
</pre>
 
=={{header|F_Sharp|F#}}==
This task uses [https://rosettacode.org/wiki/Sum_of_divisors#F.23]
<langsyntaxhighlight lang="fsharp">
// Zumkeller numbers: Nigel Galloway. May 16th., 2021
let rec fG n g=match g with h::_ when h>=n->h=n |h::t->fG n t || fG(n-h) t |_->false
Line 1,854 ⟶ 2,080:
Seq.initInfinite((*)2>>(+)1)|>Seq.map(fun n->(n,sod n))|>Seq.filter(fun(n,g)->fN n g)|>Seq.take 40|>Seq.iter(fun(n,_)->printf "%d " n); printfn "\n"
Seq.initInfinite((*)2>>(+)1)|>Seq.filter(fun n->n%10<>5)|>Seq.map(fun n->(n,sod n))|>Seq.filter(fun(n,g)->fN n g)|>Seq.take 40|>Seq.iter(fun(n,_)->printf "%d " n); printfn "\n"
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,863 ⟶ 2,089:
81081 153153 171171 189189 207207 223839 243243 261261 279279 297297 351351 459459 513513 567567 621621 671517 729729 742203 783783 793611 812889 837837 891891 908523 960687 999999 1024947 1054053 1072071 1073709 1095633 1108107 1145529 1162161 1198197 1224531 1270269 1307691 1324323 1378377
</pre>
 
=={{header|Factor}}==
{{works with|Factor|0.99 2019-10-06}}
<langsyntaxhighlight lang="factor">USING: combinators grouping io kernel lists lists.lazy math
math.primes.factors memoize prettyprint sequences ;
 
Line 1,906 ⟶ 2,133:
 
"First 40 odd Zumkeller numbers not ending with 5:" print
40 odd-zumkellers-no-5 8 show</langsyntaxhighlight>
{{out}}
<pre>
Line 1,937 ⟶ 2,164:
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">package main
 
import "fmt"
Line 2,027 ⟶ 2,254:
}
fmt.Println()
}</langsyntaxhighlight>
 
{{out}}
Line 2,060 ⟶ 2,287:
=={{header|Haskell}}==
{{Trans|Python}}
<langsyntaxhighlight lang="haskell">import Data.List (group, sort)
import Data.List.Split (chunksOf)
import Data.Numbers.Primes (primeFactors)
Line 2,132 ⟶ 2,359:
 
justifyRight :: Int -> Char -> String -> String
justifyRight n c = (drop . length) <*> (replicate n c <>)</langsyntaxhighlight>
{{Out}}
<pre>First 220 Zumkeller numbers:
Line 2,164 ⟶ 2,391:
14805 15015 15435 16065 16695 17325 17955 18585 19215 19305</pre>
 
=={{header|J}}==
Implementation:<syntaxhighlight lang="J>divisors=: {{ \:~ */@>,{ (^ i.@>:)&.">/ __ q: y }}
zum=: {{
if. 2|s=. +/divs=. divisors y do. 0
elseif. 2|y do. (0<k) * 0=2|k=. s-2*y
else. s=. -:s for_d. divs do. if. d<:s do. s=. s-d end. end. s=0
end.
}}@></syntaxhighlight>
 
Task examples:<syntaxhighlight lang="J"> 10 22$1+I.zum 1+i.1000 NB. first 220 Zumkeller numbers
6 12 20 24 28 30 40 42 48 54 56 60 66 70 78 80 84 88 90 96 102 104
108 112 114 120 126 132 138 140 150 156 160 168 174 176 180 186 192 198 204 208 210 216
220 222 224 228 234 240 246 252 258 260 264 270 272 276 280 282 294 300 304 306 308 312
318 320 330 336 340 342 348 350 352 354 360 364 366 368 372 378 380 384 390 396 402 408
414 416 420 426 432 438 440 444 448 456 460 462 464 468 474 476 480 486 490 492 496 498
500 504 510 516 520 522 528 532 534 540 544 546 550 552 558 560 564 570 572 580 582 588
594 600 606 608 612 616 618 620 624 630 636 640 642 644 650 654 660 666 672 678 680 684
690 696 700 702 704 708 714 720 726 728 732 736 740 744 750 756 760 762 768 770 780 786
792 798 804 810 812 816 820 822 828 832 834 836 840 852 858 860 864 868 870 876 880 888
894 896 906 910 912 918 920 924 928 930 936 940 942 945 948 952 960 966 972 978 980 984
4 10$1+2*I.zum 1+2*i.1e4 NB. first 40 odd Zumkeller numbers
945 1575 2205 2835 3465 4095 4725 5355 5775 5985
6435 6615 6825 7245 7425 7875 8085 8415 8505 8925
9135 9555 9765 10395 11655 12285 12705 12915 13545 14175
14805 15015 15435 16065 16695 17325 17955 18585 19215 19305
4 10$(#~ 0~:5|])1+2*I.zum 1+2*i.1e6 NB. first 40 odd Zumkeller numbers not divisible by 5
81081 153153 171171 189189 207207 223839 243243 261261 279279 297297
351351 459459 513513 567567 621621 671517 729729 742203 783783 793611
812889 837837 891891 908523 960687 999999 1024947 1054053 1072071 1073709
1095633 1108107 1145529 1162161 1198197 1224531 1270269 1307691 1324323 1378377</syntaxhighlight>
=={{header|Java}}==
<langsyntaxhighlight lang="java">
import java.util.ArrayList;
import java.util.Collections;
Line 2,278 ⟶ 2,535:
 
}
</syntaxhighlight>
</lang>
 
{{out}}
Line 2,307 ⟶ 2,564:
1095633 1108107 1145529 1162161 1198197 1224531 1270269 1307691 1324323 1378377
</pre>
 
=={{header|jq}}==
{{Works with|jq|1.5}}
 
From a practical point of view, jq is not well-suited to these tasks,
e.g. using the program shown here, the first task (computing the first 220 Zumkeller numbers)
takes about 1 second.
 
The main point of interest here, therefore, is the partitioning
function, or rather how a generic partitioning function that
generates a stream of partitions is easily transformed into a
specialized function that prunes irrelevant partitions efficiently.
<syntaxhighlight lang="jq"># The factors, sorted
def factors:
. as $num
| reduce range(1; 1 + sqrt|floor) as $i
([];
if ($num % $i) == 0 then
($num / $i) as $r
| if $i == $r then . + [$i] else . + [$i, $r] end
else .
end
| sort) ;
 
# If the input is a sorted array of distinct non-negative integers,
# then the output will be a stream of [$x,$y] arrays,
# where $x and $y are non-empty arrays that partition the
# input, and where ($x|add) == $sum.
# If [$x,$y] is emitted, then [$y,$x] will not also be emitted.
# The items in $x appear in the same order as in the input, and similarly
# for $y.
#
def distinct_partitions($sum):
# input: [$array, $n, $lim] where $n>0
# output: a stream of arrays, $a, each with $n distinct items from $array,
# preserving the order in $array, and such that
# add == $lim
def p:
. as [$in, $n, $lim]
| if $n==1 # this condition is very common so it saves time to check early on
then ($in | bsearch($lim)) as $ix
| if $ix < 0 then empty
else [$lim]
end
else ($in|length) as $length
| if $length <= $n then empty
elif $length==$n then $in | select(add == $lim)
elif ($in[-$n:]|add) < $lim then empty
else ($in[:$n]|add) as $rsum
| if $rsum > $lim then empty
elif $rsum == $lim then "amazing" | debug | $in[:$n]
else range(0; 1 + $length - $n) as $i
| [$in[$i]] + ([$in[$i+1:], $n-1, $lim - $in[$i]]|p)
end
end
end;
range(1; (1+length)/2) as $i
| ([., $i, $sum]|p) as $pi
| [ $pi, (. - $pi)]
| select( if (.[0]|length) == (.[1]|length) then (.[0] < .[1]) else true end) #1
;
 
def zumkellerPartitions:
factors
| add as $sum
| if $sum % 2 == 1 then empty
else distinct_partitions($sum / 2)
end;
 
def is_zumkeller:
first(factors
| add as $sum
| if $sum % 2 == 1 then empty
else distinct_partitions($sum / 2)
| select( (.[0]|add) == (.[1]|add)) // ("internal error: \(.)" | debug | empty) #2
end
| true)
// false;</syntaxhighlight><syntaxhighlight lang="jq">## The tasks:
 
"First 220:", limit(220; range(2; infinite) | select(is_zumkeller)),
""
"First 40 odd:", limit(40; range(3; infinite; 2) | select(is_zumkeller))</syntaxhighlight>
{{out}}
<pre>
First 220:
6
12
20
24
28
...
984
 
First 40 odd:
945
1575
2205
2835
3465
...
19305</pre>
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia">using Primes
 
function factorize(n)
Line 2,357 ⟶ 2,716:
println("\n\nFirst 40 odd Zumkeller numbers not ending with 5:")
printconditionalnum((n) -> isodd(n) && (string(n)[end] != '5') && iszumkeller(n), 40, 8)
</langsyntaxhighlight>{{out}}
<pre>
First 220 Zumkeller numbers:
Line 2,391 ⟶ 2,750:
=={{header|Kotlin}}==
{{trans|Java}}
<langsyntaxhighlight lang="scala">import java.util.ArrayList
import kotlin.math.sqrt
 
Line 2,499 ⟶ 2,858:
return divisors
}
}</langsyntaxhighlight>
{{out}}
<pre>First 220 Zumkeller numbers:
Line 2,527 ⟶ 2,886:
 
=={{header|Lobster}}==
<langsyntaxhighlight lang="Lobster">import std
 
// Derived from Julia and Python versions
Line 2,587 ⟶ 2,946:
print "\n\n40 odd Zumkeller numbers:"
printZumkellers(40, true)
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 2,621 ⟶ 2,980:
14805 15015 15435 16065 16695 17325 17955 18585 19215 19305
</pre>
 
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<syntaxhighlight lang="Mathematica">ClearAll[ZumkellerQ]
ZumkellerQ[n_] := Module[{d = Divisors[n], t, ds, x},
ds = Total[d];
If[Mod[ds, 2] == 1,
False
,
t = CoefficientList[Product[1 + x^i, {i, d}], x];
t[[1 + ds/2]] > 0
]
];
i = 1;
res = {};
While[Length[res] < 220,
r = ZumkellerQ[i];
If[r, AppendTo[res, i]];
i++;
];
res
 
i = 1;
res = {};
While[Length[res] < 40,
r = ZumkellerQ[i];
If[r, AppendTo[res, i]];
i += 2;
];
res</syntaxhighlight>
{{out}}
<pre>{6,12,20,24,28,30,40,42,48,54,56,60,66,70,78,80,84,88,90,96,102,104,108,112,114,120,126,132,138,140,150,156,160,168,174,176,180,186,192,198,204,208,210,216,220,222,224,228,234,240,246,252,258,260,264,270,272,276,280,282,294,300,304,306,308,312,318,320,330,336,340,342,348,350,352,354,360,364,366,368,372,378,380,384,390,396,402,408,414,416,420,426,432,438,440,444,448,456,460,462,464,468,474,476,480,486,490,492,496,498,500,504,510,516,520,522,528,532,534,540,544,546,550,552,558,560,564,570,572,580,582,588,594,600,606,608,612,616,618,620,624,630,636,640,642,644,650,654,660,666,672,678,680,684,690,696,700,702,704,708,714,720,726,728,732,736,740,744,750,756,760,762,768,770,780,786,792,798,804,810,812,816,820,822,828,832,834,836,840,852,858,860,864,868,870,876,880,888,894,896,906,910,912,918,920,924,928,930,936,940,942,945,948,952,960,966,972,978,980,984}
{945,1575,2205,2835,3465,4095,4725,5355,5775,5985,6435,6615,6825,7245,7425,7875,8085,8415,8505,8925,9135,9555,9765,10395,11655,12285,12705,12915,13545,14175,14805,15015,15435,16065,16695,17325,17955,18585,19215,19305}</pre>
 
=={{header|Nim}}==
{{trans|Go}}
<langsyntaxhighlight lang="Nim">import math, strutils
 
template isEven(n: int): bool = (n and 1) == 0
Line 2,694 ⟶ 3,085:
inc count
stdout.write if count mod 8 == 0: '\n' else: ' '
inc n, 2</langsyntaxhighlight>
 
{{out}}
Line 2,722 ⟶ 3,113:
960687 999999 1024947 1054053 1072071 1073709 1095633 1108107
1145529 1162161 1198197 1224531 1270269 1307691 1324323 1378377</pre>
 
=={{header|PARI/GP}}==
{{trans|Mathematica_/_Wolfram_Language}}
<syntaxhighlight lang="PARI/GP">
\\ Define a function to check if a number is Zumkeller
isZumkeller(n) = {
my(d = divisors(n));
my(ds = sum(i=1, #d, d[i])); \\ Total of divisors
if (ds % 2, return(0)); \\ If sum of divisors is odd, return false
my(coeffs = vector(ds+1, i, 0)); \\ Create a vector to store coefficients
coeffs[1] = 1;
for(i=1, #d, coeffs = Pol(coeffs) * (1 + x^d[i]); coeffs = Vecrev(coeffs); if(#coeffs > ds + 1, coeffs = coeffs[^1])); \\ Generate coefficients
coeffs[ds \ 2 + 1] > 0; \\ Check if the middle coefficient is positive
}
 
\\ Generate a list of Zumkeller numbers
ZumkellerList(limit) = {
my(res = List(), i = 1);
while(#res < limit,
if(isZumkeller(i), listput(res, i));
i++;
);
Vec(res); \\ Convert list to vector
}
 
\\ Generate a list of odd Zumkeller numbers
OddZumkellerList(limit) = {
my(res = List(), i = 1);
while(#res < limit,
if(isZumkeller(i), listput(res, i));
i += 2; \\ Only check odd numbers
);
Vec(res); \\ Convert list to vector
}
 
\\ Call the functions to get the lists
zumkeller220 = ZumkellerList(220);
oddZumkeller40 = OddZumkellerList(40);
 
\\ Print the results
print(zumkeller220);
print(oddZumkeller40);
</syntaxhighlight>
 
{{out}}
<pre>
[6, 12, 20, 24, 28, 30, 40, 42, 48, 54, 56, 60, 66, 70, 78, 80, 84, 88, 90, 96, 102, 104, 108, 112, 114, 120, 126, 132, 138, 140, 150, 156, 160, 168, 174, 176, 180, 186, 192, 198, 204, 208, 210, 216, 220, 222, 224, 228, 234, 240, 246, 252, 258, 260, 264, 270, 272, 276, 280, 282, 294, 300, 304, 306, 308, 312, 318, 320, 330, 336, 340, 342, 348, 350, 352, 354, 360, 364, 366, 368, 372, 378, 380, 384, 390, 396, 402, 408, 414, 416, 420, 426, 432, 438, 440, 444, 448, 456, 460, 462, 464, 468, 474, 476, 480, 486, 490, 492, 496, 498, 500, 504, 510, 516, 520, 522, 528, 532, 534, 540, 544, 546, 550, 552, 558, 560, 564, 570, 572, 580, 582, 588, 594, 600, 606, 608, 612, 616, 618, 620, 624, 630, 636, 640, 642, 644, 650, 654, 660, 666, 672, 678, 680, 684, 690, 696, 700, 702, 704, 708, 714, 720, 726, 728, 732, 736, 740, 744, 750, 756, 760, 762, 768, 770, 780, 786, 792, 798, 804, 810, 812, 816, 820, 822, 828, 832, 834, 836, 840, 852, 858, 860, 864, 868, 870, 876, 880, 888, 894, 896, 906, 910, 912, 918, 920, 924, 928, 930, 936, 940, 942, 945, 948, 952, 960, 966, 972, 978, 980, 984]
[945, 1575, 2205, 2835, 3465, 4095, 4725, 5355, 5775, 5985, 6435, 6615, 6825, 7245, 7425, 7875, 8085, 8415, 8505, 8925, 9135, 9555, 9765, 10395, 11655, 12285, 12705, 12915, 13545, 14175, 14805, 15015, 15435, 16065, 16695, 17325, 17955, 18585, 19215, 19305]
</pre>
 
=={{header|Pascal}}==
Using sieve for primedecomposition<BR>
modified [[practical numbers]] and [[Factors_of_an_integer#using_Prime_decomposition]]
Now using the trick, that one partition sum must include n and thatimproved inrecursive most cases summing up from top to buttom gets the right sum of divs with no mental acrobaticssearch.<BR>
Limit is ~1.2e11
<lang pascal>program zumkeller;
<syntaxhighlight lang="pascal">program zumkeller;
//https://oeis.org/A083206/a083206.txt
{$IFDEF FPC}
{$MODE DELPHI} {$OPTIMIZATION ON,ALL} {$COPERATORS ON}
// {$O+,I+}
{$ELSE}
{$APPTYPE CONSOLE}
Line 2,738 ⟶ 3,181:
//######################################################################
//prime decomposition
const
//HCN(86) > 1.2E11 = 128,501,493,120 count of divs = 4096 7 3 1 1 1 1 1 1 1
HCN_DivCnt = 4096;
//stop never ending recursion
RECCOUNTMAX = 100*1000*1000;
DELTAMAX = 1000*1000;
type
tItem = Uint32Uint64;
tDivisors = array [0..HCN_DivCnt-1] of tItem;
tpDivisor = pUint32pUint64;
const
 
SizePrDeFe = 12697;//*72 <= 1 or 2 Mb ~ level 2 cache -32kB for DIVS
tPot = record
type
potPrim,
tdigits = packed record
potMax :Uint32;
dgtDgts : array [0..31] of Uint32;
end;
end;
 
//the first number with 11 different divisors =
tprimeFac = record
// 2*3*5*7*11*13*17*19*23*29*31 = 2E11
pfPrims : array[0..15] of tPot;
tprimeFac = packed record
pfSumOfDivs :Uint64;
pfCntpfSumOfDivs,
pfRemain : Uint64; //n div (p[0]^[pPot[0] *...) can handle primes <=821641^2 = 6.7e11
pfDivCnt,
pfNum,pfdummypfpotPrim : array[0..9] of : Uint32UInt32;//+10*4 = 56 Byte
pfpotMax : array[0..9] of byte; //10 = 66
pfMaxIdx : Uint16; //68
pfDivCnt : Uint32; //72
end;
 
tPrimeDecompField = array[0..SizePrDeFe-1] of tprimeFac;
tPrimes = array[0..65535] of Uint32;
 
type
tSmallPrimes = array[0..6541] of Word;
var
SmallPrimes: tSmallPrimestPrimes;
//######################################################################
isSmallPrimesInited : boolean = false;
//prime decomposition
 
procedure InitSmallPrimes;
//only odd numbers
const
MAXLIMIT = (821641-1) shr 1;
var
pr : array[0..MAXLIMIT] of byte;
pr,testPr,j,maxprimidx: Uint32;
p,j,d,flipflop :NativeUInt;
isPrime : boolean;
Begin
maxprimidx := 0;
SmallPrimes[0] := 2;
fillchar(pr[0],SizeOf(pr),#0);
pr := 3;
p := 0;
repeat
isprime := true;
j := 0;
repeat
testPrp :+= SmallPrimes[j];1
IF sqr(testPr) >until pr[p]= then0;
j := break(p+1)*p*2;
if If pr mod testPr = 0j>MAXLIMIT then
BeginBREAK;
isprimed := false2*p+1;
break;repeat
endpr[j] := 1;
j += d;
until j>MAXLIMIT;
until false;
 
SmallPrimes[1] := 3;
SmallPrimes[2] := 5;
j := 3;
d := 7;
flipflop := 3-1;
p := 3;
repeat
if pr[p] = 0 then
begin
SmallPrimes[j] := d;
inc(j);
until falseend;
d += 2*flipflop;
p+=flipflop;
flipflop := 3-flipflop;
until (p > MAXLIMIT) OR (j>High(SmallPrimes));
end;
 
function OutPots(const pD:tprimeFac;n:NativeInt):Ansistring;
if isprime then
var
s: String[31];
Begin
str(n,s);
result := s+' :';
with pd do
begin
str(pfDivCnt:3,s);
result += s+' : ';
For n := 0 to pfMaxIdx-1 do
Begin
inc(maxprimidx);if n>0 then
SmallPrimes[maxprimidx]: result += pr'*';
str(pFpotPrim[n],s);
result += s;
if pfpotMax[n] >1 then
Begin
str(pfpotMax[n],s);
result += '^'+s;
end;
end;
If pfRemain >1 then
inc(pr,2);
Begin
until pr > 1 shl 16 -1;
str(pfRemain,s);
isSmallPrimesInited:= true;
result += '*'+s;
end;
str(pfSumOfDivs,s);
result += '_SoD_'+s+'<';
end;
end;
 
function CnvtoBASE(var dgt:tDigits;n:Uint64;base:NativeUint):NativeInt;
function DivCount(const pD:tprimeFac):NativeUInt;inline;
//n must be multiple of base
begin
var
result := pD.pfDivCnt;
q,r: Uint64;
end;
i : NativeInt;
Begin
with dgt do
Begin
fillchar(dgtDgts,SizeOf(dgtDgts),#0);
i := 0;
// dgtNum:= n;
n := n div base;
result := 0;
repeat
r := n;
q := n div base;
r -= q*base;
n := q;
dgtDgts[i] := r;
inc(i);
until (q = 0);
 
result := 0;
function SumOfDiv(const pD:tprimeFac):Uint64;inline;
while (result<i) AND (dgtDgts[result] = 0) do
begin
inc(result);
result := pD.pfSumOfDivs;
inc(result);
end;
end;
 
function IncByBaseInBase(var dgt:tDigits;base:NativeInt):NativeInt;
procedure PrimeDecomposition(n:Uint32;var res:tprimeFac);
Label
Finished;
var
q :NativeInt;
DivSum,fac:Uint64;
i,pr,cnt,DivCnt,quot{to minimize divisions} : Uint32;
Begin
with dgt do
if Not(isSmallPrimesInited) then
InitSmallPrimes;
//already done
if res.pfNum = n then
EXIT;
res.pfNum := n;
cnt := 0;
DivCnt := 1;
DivSum := 1;
i := 0;
if n <= 1 then
Begin
withresult res.pfPrims[0]:= do0;
q := dgtDgts[result]+1;
Begin
// potPrim := ninc(dgtNum,base);
if q potMax= base := 1;then
begin
repeat
dgtDgts[result] := 0;
inc(result);
q := dgtDgts[result]+1;
until q <> base;
end;
cntdgtDgts[result] := 1q;
result +=1;
end
elseend;
end;
Begin
 
pr := 2;
procedure SieveOneSieve(var pdf:tPrimeDecompField;n:nativeUInt);
IF 2*2>n then
var
GOTO Finished;
dgt:tDigits;
quot := n div 2;
i, j, k,pr,fac : NativeUInt;
IF 2*quot = n then
begin
//init
for i := 0 to High(pdf) do
with pdf[i] do
Begin
withpfDivCnt res:= do1;
pfSumOfDivs := 1;
with pfPrims[Cnt] do
pfRemain := Beginn+i;
potPrimpfMaxIdx := 20;
potMax := 0;
fac := 2;
repeat
n := quot;
quot := quot div 2;
inc(potMax);
fac *= 2;
until pr*quot <> n;
DivCnt *= (potMax+1);
DivSum *= (fac-1)DIV (2-1);
end;
inc(Cnt);
end;
 
//first 2 prmake :=n+i 3;even
i := IF 3*3>n thenAND 1;
repeat
GOTO Finished;
quotwith :=pdf[i] n div 3;do
IF 3*quot =if n+i > 0 then
begin
with res doj := BsfQWord(n+i);
Begin pfMaxIdx := 1;
with pfPrimspfpotPrim[Cnt0] do:= 2;
BeginpfpotMax[0] := j;
potPrimpfRemain := 3(n+i) shr j;
potMaxpfSumOfDivs := 0(1 shl (j+1))-1;
facpfDivCnt := 3j+1;
repeat
n := quot;
quot := quot div 3;
inc(potMax);
fac *= 3;
until pr*quot <> n;
DivCnt *= (potMax+1);
DivSum *= (fac-1) DIV (3-1);
end;
end;
i += inc(Cnt)2;
until i end>High(pdf);
 
// i now index in SmallPrimes
pr := 5;
i := 0;
IF 5*5>n then
repeat
GOTO Finished;
//search next prime that is in bounds of sieve
quot := n div 5;
repeat
IF 5*quot = n then
begin inc(i);
if i >= High(SmallPrimes) then
with res do
Begin BREAK;
pr := with pfPrimsSmallPrimes[Cnti] do;
k := Beginpr-n MOD pr;
if (k = pr) potPrimAND :=(n>0) 5;then
potMax k:= 0;
if k < SizePrDeFe fac := 5;then
repeatbreak;
until n := quotfalse;
if i >= High(SmallPrimes) then
quot := quot div 5;
inc(potMax)BREAK;
//no need to use higher fac *= 5;primes
untilif pr*quotpr <> n;+SizePrDeFe then
DivCnt *= (potMax+1)BREAK;
DivSum *= (fac-1) DIV (5-1);
end;
end;
inc(Cnt);
end;
 
pr// :=j 7;is power of prime
j := CnvtoBASE(dgt,n+k,pr);
IF 7*7>n then
repeat
GOTO Finished;
quot := nwith divpdf[k] 7;do
IF 7*quot = n then
begin
with res do
Begin
with pfPrimspfpotPrim[CntpfMaxIdx] do:= pr;
BeginpfpotMax[pfMaxIdx] := j;
pfDivCnt potPrim :*= 7j+1;
potMaxfac := 0pr;
fac := 7;repeat
repeatpfRemain := pfRemain DIV pr;
n := quotdec(j);
fac quot :*= quot div 7pr;
until j<= inc(potMax)0;
facpfSumOfDivs *= 7(fac-1)DIV(pr-1);
until pr*quot <> ninc(pfMaxIdx);
DivCnt *= (potMax+1);
DivSum *= (fac-1) DIV (7-1);
end;
end;
inc(Cnt)k += pr;
j := IncByBaseInBase(dgt,pr);
end;
until k >= SizePrDeFe;
until false;
 
//correct sum of & count of divisors
pr := 11;
for i := 0 to High(pdf) do
IF 11*11>n then
Begin
GOTO Finished;
quotwith :=pdf[i] n div 11;do
IF 11*quot = n then
begin
withj res:= dopfRemain;
Beginif j <> 1 then
with pfPrims[Cnt] dobegin
BeginpfSumOFDivs *= (j+1);
pfDivCnt potPrim :*= 112;
potMax := 0;
fac := 11;
repeat
n := quot;
quot := quot div 11;
inc(potMax);
fac *= 11;
until pr*quot <> n;
DivCnt *= (potMax+1);
DivSum *= (fac-1) DIV (11-1);
end;
end;
inc(Cnt);
end;
end;
end;
//prime decomposition
//######################################################################
procedure Init_Check_rec(const pD:tprimeFac;var Divs,SumOfDivs:tDivisors);forward;
 
var
pr := 13;
{$ALIGN 32}
IF 13*13>n then
PrimeDecompField:tPrimeDecompField;
GOTO Finished;
{$ALIGN 32}
quot := n div 13;
Divs :tDivisors;
IF 13*quot = n then
SumOfDivs : tDivisors;
begin
DivUsedIdx : tDivisors;
with res do
Begin
with pfPrims[Cnt] do
Begin
potPrim := 13;
potMax := 0;
fac := 13;
repeat
n := quot;
quot := quot div 13;
inc(potMax);
fac *= 13;
until pr*quot <> n;
DivCnt *= (potMax+1);
DivSum *= (fac-1) DIV (13-1);
end;
end;
inc(Cnt);
end;
i := 6;
 
pDiv :tpDivisor;
repeat
T0: Int64;
pr := SmallPrimes[i];
count,rec_Cnt: NativeInt;
depth : Int32;
finished :Boolean;
 
procedure Check_rek_depth(SoD : Int64;i: NativeInt);
IF pr*pr>n then
var
Break;
sum : Int64;
begin
if finished then
EXIT;
inc(rec_Cnt);
 
WHILE (i>0) AND (pDiv[i]>SoD) do
quot := n div pr;
dec(i);
IF pr*quot = n then
 
with res do
while i >= 0 Begindo
Begin
with pfPrims[Cnt] do
DivUsedIdx[depth] := pDiv[i];
Begin
potPrimsum := prSoD-pDiv[i];
if sum potMax := 0; then
begin
fac := pr;
finished := repeattrue;
n := quotEXIT;
end;
quot := quot div pr;
incdec(potMaxi);
fac *= princ(depth);
if (i>= 0) AND (sum <= until pr*quot <>SumOfDivs[i]) n;then
DivCnt *= Check_rek_depth(potMax+1sum,i);
if finished then
DivSum *= (fac-1)DIV(pr-1);
endEXIT;
// DivUsedIdx[depth] := 0;
inc(Cnt);
enddec(depth);
inc(i)end;
end;
until false;
 
Finished:
procedure Out_One_Sol(const pd:tprimefac;n:NativeUInt;isZK : Boolean);
//a big prime left over?
var
IF n > 1 then
sum : with res doNativeInt;
Begin
if n< 7 then
exit;
with pd do
begin
writeln(OutPots(pD,n));
if isZK then
Begin
Init_Check_rec(pD,Divs,SumOfDivs);
with pfPrims[Cnt] do
Check_rek_depth(pfSumOfDivs shr 1-n,pFDivCnt-1);
write(pfSumOfDivs shr 1:10,' = ');
sum := n;
while depth >= 0 do
Begin
potPrimsum :+= nDivUsedIdx[depth];
potMax := 1write(DivUsedIdx[depth],'+');
dec(depth);
end;
incwrite(Cntn,' = ',sum);
DivCnt *= 2;end
else
DivSum *= n+1;
write(' no zumkeller ');
end;
end;
res.pfCnt:= cnt;
res.pfDivCnt := DivCnt;
res.pfSumOfDivs := DivSum;
end;
 
Line 3,055 ⟶ 3,526:
end;
 
procedure GetDivs(const pD:tprimeFac;var Divs,SumOfDivs:tDivisors);
var
pDivs : tpDivisor;
i,len,j,l,p,pPot,k : NativeIntUInt64;
i,len,j,l,p,k: Int32;
Begin
i := DivCount(pD).pfDivCnt;
setlength(Divs,0);
setlength(Divs,i);
pDivs := @Divs[0];
pDivs[0] := 1;
len := 1;
l := 1;
For i := 0 towith pD.pfCnt-1 do
Begin
with pD.pfPrims[i] do
For i := 0 to pfMaxIdx-1 do
Begin
begin
//Multiply every divisor before with the new primefactors
//and append them to the list
k := potMax-1pfpotMax[i];
p := potPrimpfpotPrim[i];
pPot :=1;
repeat
Line 3,083 ⟶ 3,554:
end;
dec(k);
until k<=0;
len := l;
end;
p := pfRemain;
If p >1 then
begin
For j := 0 to len-1 do
Begin
pDivs[l]:= p*pDivs[j];
inc(l);
end;
len := l;
end;
end;
//Sort. Insertsort much faster than QuickSort in this special case
InsertSort(pDivs,0,len-1);
 
pPot := 0;
For i := 0 to len-1 do
begin
pPot += pDivs[i];
SumOfDivs[i] := pPot;
end;
end;
 
functionprocedure OutPotsInit_Check_rec(const pD:tprimeFac);var Divs,SumOfDivs:AnsistringtDivisors);
begin
var
GetDivs(pD,Divs,SUmOfDivs);
s: String;
ifinished := NativeIntfalse;
depth := 0;
Begin
pDiv := @Divs[0];
str(pD.pfNum:10,s);
result := s+' : ';
For i := 0 to pD.pfCnt-1 do
with pD.pfPrims[i] do
Begin
if i>0 then
result += '*';
str(potPrim,s);
result += s;
if potMax >1 then
Begin
str(potMax,s);
result += '^'+s;
end;
end;
end;
//prime decomposition
//######################################################################
type
tSol = array of Uint32;
tpHasSum =pByte;
var
HasSum: array of byte;
Divs:tDivisors;
sol : tSol;
T0: Int64;
count: NativeInt;
checked :Boolean;
 
procedure Check_rek(SoD : Int64;i: NativeInt);
function isZumKeller(HalfSumOfDivs_N: NativeUInt;const Divs:tDivisors):boolean;
//mark sum and than shift by next divisor == add
//for practical numbers every sum must be marked
//modified for zumkeller
var
hs0sum : tpHasSumInt64;
pU64 :Uint64;
pDivs : tpDivisor;
j,maxlimit : NativeInt;
i: NativeUInt;
begin
if finished then
pDIvs := @Divs[0];
maxlimit := 0EXIT;
if rec_Cnt >RECCOUNTMAX then
j:= HalfSumOfDivs_N;
repeatbegin
IFrec_Cnt maxLimit>:=j then-1;
finished := EXIT(true);
i := pDivs[0]exit;
IF i > maxlimit+1 then
break;
maxlimit += i;
inc(pDivs);
until false;
 
i := ((HalfSumOfDivs_N-1) DIV 8 +1)*8;
if High(HasSum) < i then
Begin
setlength(HasSum,0);
setlength(HasSum,i+8);
end;
inc(rec_Cnt);
hs0 := @HasSum[0];
j := (maxLimit SHR 3) shl 3;
fillQword(HasSum[(maxLimit SHR 3) shl 3],(i-j) shr 3+1,0);
fillchar(HasSum[0],maxLimit+1,#1); //minimal 0
 
WHILE (i>0) AND (pDiv[i]>SoD) do
repeat
j:= HalfSumOfDivs_Ndec(i);
if hs0[j] <> 0 then
EXIT(true);
i := pDivs[0];
if maxLimit > j-i then
BREAK;
inc(pDivs);
//next sum
j := MaxLimit;
hs0 := @hs0[j+1];
repeat
dec(hs0);
dec(j);
hs0[i] := hs0[i] OR hs0[0];
until j< 0;
maxlimit += i;
until false;
 
while i >= 0 do
repeat
Begin
j:= HalfSumOfDivs_N;
ifsum hs0:= SoD-pDiv[ji] <> 0 then;
if sum EXIT(true);= 0 then
i := pDivs[0];begin
j finished := j-itrue;
if j <0 thenEXIT;
Exit(false)end;
incdec(pDivsi);
if (i>= 0) AND (sum <= SumOfDivs[i]) then
//next sum
hs0 := @hs0[j+1]Check_rek(sum,i);
if finished then
repeat
dec(hs0)EXIT;
end;
dec(j);
hs0[i] := (hs0[0] OR hs0[i]);
until j< 0;
until false;
end;
 
function GetZumKeller(n: Uint32NativeUint;var primeDecomppD:tPrimefac): boolean;
var
SoD,sum : Int64;
pDivs:tpDivisor;
sumDiv_cnt,tmpi,SoD pracLmt: Int64NativeInt;
h,i,j,min_j: NativeInt;
 
begin
checkedrec_Cnt := true0;
SoD:= pd.pfSumOfDivs;
PrimeDecomposition(n,primeDecomp);
sum := SumOfDiv(primeDecomp);
//sum must be even and n not deficient
if Odd(sumSoD) or (sumSoD<2*n) THEN
EXIT(false);
//if Odd(n) then Exit(Not(odd(sum)));// to be tested
 
SoD := SoD shr 1-n;
if Not(odd(n)) then
if ((n mod 18) in [6,12]) then
EXIT(true);
 
//Now one needs to get the divisors
GetDivs(primeDecomp,Divs);
pDivs := @Divs[0];
 
//erase divisor = n, one partition includes n
SoD := SumOfDiv(primeDecomp) shr 1-n;
If SoD < 2 then //0,1 is always true
Exit(true);
sum := SoD;
 
Div_cnt := pD.pfDivCnt;
//search minmal index to reach sum of divisors
 
min_j := 0;
if sum > 0Not(odd(n)) then
if ((n mod 18) in [6,12]) then
Begin
repeat
sum -= pDivs[min_j];
inc(min_j);
until sum <= 0;
IF sum = 0 then
EXIT(true);
dec(min_j,2);
end;
 
//onlyNow 2one loopsneeds asto startget pointthe of searchdivisors
Init_check_rec(pD,Divs,SumOfDivs);
j := DivCount(primeDecomp)-2;
 
repeat
i pracLmt:= j0;
if Not(odd(n)) then
while (i >= min_j) AND (pDivs[i] > SoD) do
begin
dec(i);
whileFor i >:= min_j1 to Div_Cnt do
Begin
sum :=SoD-pDivs SumOfDivs[i];
ifIf (sum+1<Divs[i+1]) =AND 0(sum<SoD) then
EXIT(TRUE);
h:= i-1;
while (h>=0) AND (sum < pDivs[h]) do
dec(h);
while h >= 0 do
Begin
tmppracLmt := sum-pDivs[h]i;
if tmp = 0 thenBREAK;
EXIT(TRUE);
if tmp > 0 then
sum :=tmp;
dec(h);
end;
IF dec(isum>=SoD) then break;
end;
if pracLmt = 0 then
dec(j);
until j > min_j Exit(true);
end;
//number is practical followed by one big prime
if pracLmt = (Div_Cnt-1) shr 1 then
begin
i := SoD mod Divs[pracLmt+1];
with pD do
begin
if pfRemain > 1 then
EXIT((pfRemain<=i) OR (i<=sum))
else
EXIT((pfpotPrim[pfMaxIdx-1]<=i)OR (i<=sum));
end;
end;
 
Begin
checked := false;
IF Div_cnt <= HCN_DivCnt then
sum := SoD;
Begin
result := isZumKeller(sum,Divs);
Check_rek(SoD,Div_cnt-1);
IF rec_Cnt = -1 then
exit(true);
exit(finished);
end;
end;
result := false;
end;
 
procedure CheckSpecial(n:Uint32;var primeDecomp:tPrimeFac);
var
isZKOfs,i,n : booleanNativeUInt;
Max: NativeUInt;
Begin
 
isZK:=GetZumKeller(n,primeDecomp);
procedure Init_Sieve(n:NativeUint);
writeln(n:10,' SumOfDivs ',SumOfDiv(primeDecomp):11,' CountOfDivs ',DivCount(primeDecomp),' isZk ',isZK);
//Init Sieve i,oFs are Global
writeln(OutPots(primeDecomp));
begin
i := n MOD SizePrDeFe;
Ofs := (n DIV SizePrDeFe)*SizePrDeFe;
SieveOneSieve(PrimeDecompField,Ofs);
end;
 
procedure OutSolGetSmall(const solMaxIdx:tsol;colWidth,ColCount:NativeIntInt32);
var
ZK: Array of Uint32;
i,col: NativeInt;
idx: UInt32;
Begin
If MaxIdx<1 then
col := ColCount;
EXIT;
For i := 0 to High(sol) do
writeln('The first ',MaxIdx,' zumkeller numbers');
begin
Init_Sieve(0);
write(' ',Sol[i]:colWidth-1);
decsetlength(colZK,MaxIdx);
idx if col := 0 thenLow(ZK);
repeat
if GetZumKeller(n,PrimeDecompField[i]) then
Begin
writelnZK[idx] := n;
col := ColCountinc(idx);
end;
inc(i);
inc(n);
If i > High(PrimeDecompField) then
begin
dec(i,SizePrDeFe);
inc(ofs,SizePrDeFe);
SieveOneSieve(PrimeDecompField,Ofs);
end;
until idx >= MaxIdx;
For idx := 0 to MaxIdx-1 do
begin
if idx MOD 20 = 0 then
writeln;
write(ZK[idx]:4);
end;
setlength(ZK,0);
writeln;
writeln;
end;
 
procedure GetOdd(MaxIdx:Int32);
var
ZK: Array of Uint32;
primeDecomp : tPrimeFac;
n,checkCntidx: NativeIntUInt32;
Begin
BEGIN
If MaxIdx<1 then
setlength(HasSum,1);
T0 := GetTickCount64EXIT;
writeln('CountThe offirst odd 40 zumkeller numbers up to 1,000,000');
n := 1;
Init_Sieve(n);
count :=0;
setlength(ZK,MaxIdx);
idx := Low(ZK);
repeat
if GetZumKeller(n,primeDecompPrimeDecompField[i]) then
Begin
ZK[idx] := n;
inc(idx);
end;
inc(i,2);
inc(n,2);
If i > High(PrimeDecompField) then
begin
IF checked thendec(i,SizePrDeFe);
inc(checkCntofs,SizePrDeFe);
incSieveOneSieve(countPrimeDecompField,Ofs);
end;
until idx inc(n,1)>= MaxIdx;
For idx := 0 to MaxIdx-1 do
until n > 1000*1000;
begin
writeln(count:10,n-1:10,' pre checked ',checkCnt);
if idx MOD (80 DIV 8) = 0 then
T0 := GetTickCount64-T0;
writeln;
writeln('runtime ',T0/1000:0:3,' s');
write(ZK[idx]:8);
end;
setlength(ZK,0);
writeln;
writeln;
end;
 
procedure GetOddNot5(MaxIdx:Int32);
writeln(#10,'First 220 zumkeller');
var
T0 := GetTickCount64;
ZK: Array of Uint32;
idx: UInt32;
Begin
If MaxIdx<1 then
EXIT;
writeln('The first odd 40 zumkeller numbers not ending in 5');
n := 1;
Init_Sieve(n);
count :=0;
setlength(solZK,220MaxIdx);
idx := Low(ZK);
repeat
if GetZumKeller(n,primeDecompPrimeDecompField[i]) then
Begin
ZK[idx] := n;
inc(idx);
end;
inc(i,2);
inc(n,2);
If n mod 5 = 0 then
begin
sol[count] := ninc(i,2);
inc(countn,2);
end;
If i > High(PrimeDecompField) then
inc(n,1);
until count >= length(sol);
OutSol(sol,4,20);
T0 := GetTickCount64-T0;
writeln('runtime ',T0/1000:0:3,' s');
 
T0 := GetTickCount64;
n := 1;
count :=0;
checkCnt := 0;
setlength(sol,40);
writeln(#10,'First 40 odd zumkeller numbers');
repeat
if GetZumKeller(n,primeDecomp) then
begin
sol[count] := ndec(i,SizePrDeFe);
inc(countofs,SizePrDeFe);
SieveOneSieve(PrimeDecompField,Ofs);
if checked then
inc(checkCnt);
end;
until idx inc(n,2)>= MaxIdx;
For idx := 0 to MaxIdx-1 do
until count>=length(sol);
begin
OutSol(sol,10,8);
if idx MOD (80 DIV 8) = 0 then
writeln(count:10,n-2:10,' pre checked ',checkCnt);
writeln;
write(ZK[idx]:8);
end;
setlength(ZK,0);
writeln;
writeln;
end;
BEGIN
InitSmallPrimes;
 
T0 := GetTickCount64-T0;
GetSmall(220);
writeln('runtime ',T0/1000:0:3,' s');
GetOdd(40);
GetOddNot5(40);
 
writeln;
n := 1;//8996229720;//1;
Init_Sieve(n);
writeln('Start ',n,' at ',i);
T0 := GetTickCount64;
nMAX := (n DIV DELTAMAX+1)*DELTAMAX;
count := 0;
setlength(sol,40);
writeln(#10,'First 40 odd zumkeller numbers not multiple of 5');
repeat
writeln('Count of zumkeller numbers up to ',MAX:12);
if GetZumKeller(n,primeDecomp) then
beginrepeat
if GetZumKeller(n,PrimeDecompField[i]) then
sol[count] := n;
inc(count);
end inc(i);
inc(n,2);
if n modIf 5i => 0High(PrimeDecompField) then
inc(n,2);begin
until count >= length dec(soli,SizePrDeFe);
OutSol inc(solofs,10,8SizePrDeFe);
SieveOneSieve(PrimeDecompField,Ofs);
T0 := GetTickCount64-T0;
end;
writeln('runtime ',T0/1000:0:3,' s');
until n > MAX;
 
writeln(n-1:10,' tested found ',count:10,' ratio ',count/n:10:7);
MAX += DELTAMAX;
until MAX>10*DELTAMAX;
writeln('runtime ',(GetTickCount64-T0)/1000:8:3,' s');
writeln;
writeln('Count of recursion 59,641,327 for 8,996,229,720');
n := 8996229720;
Init_Sieve(n);
T0 := GetTickCount64;
Out_One_Sol(PrimeDecompField[i],n,true);
CheckSpecial(3492,primeDecomp);
writeln;
CheckSpecial(14184,primeDecomp);
writeln('runtime ',(GetTickCount64-T0)/1000:8:3,' s');
CheckSpecial(58896,primeDecomp);
END.
CheckSpecial(236448,primeDecomp);
</syntaxhighlight>
CheckSpecial(954432,primeDecomp);
CheckSpecial(2549700,primeDecomp);
CheckSpecial(10884600,primeDecomp);
T0 := GetTickCount64-T0;
writeln('runtime ',T0/1000:0:3,' s');
 
setlength(sol,0);
setlength(HasSum, 0);
//{$IFNDEF UNIX} readln; {$ENDIF}
END.</lang>
{{out}}
<pre>TIO.RUN
TIO.RUN
Count of zumkeller numbers up to 1,000,000
The first 220 zumkeller numbers
229026 1000000 pre checked 228154
runtime 3.351 s
 
First 220 zumkeller
6 12 20 24 28 30 40 42 48 54 56 60 66 70 78 80 84 88 90 96
102 104 108 112 114 120 126 132 138 140 150 156 160 168 174 176 180 186 192 198
Line 3,413 ⟶ 3,875:
906 910 912 918 920 924 928 930 936 940 942 945 948 952 960 966 972 978 980 984
 
The first odd 40 zumkeller numbers
runtime 0.000 s
 
945 1575 2205 2835 3465 4095 4725 5355 5775 5985
First 40 odd zumkeller numbers
6435 945 6615 6825 1575 7245 2205 7425 7875 2835 8085 3465 8415 8505 4095 4725 53558925
9135 5775 9555 59859765 10395 643511655 12285 661512705 12915 682513545 7245 7425 787514175
14805 808515015 15435 841516065 16695 850517325 17955 892518585 19215 9135 9555 9765 1039519305
11655 12285 12705 12915 13545 14175 14805 15015
15435 16065 16695 17325 17955 18585 19215 19305
 
The first odd 40 zumkeller numbers not ending in 5
runtime 0.001 s
 
81081 153153 171171 189189 207207 223839 243243 261261 279279 297297
First 40 odd zumkeller numbers not multiple of 5
351351 459459 513513 567567 621621 671517 729729 742203 783783 793611
81081 153153 171171 189189 207207 223839 243243 261261
812889 837837 891891 908523 960687 999999 1024947 1054053 1072071 1073709
279279 297297 351351 459459 513513 567567 621621 671517
1095633 1108107 1145529 1162161 1198197 1224531 1270269 1307691 1324323 1378377
729729 742203 783783 793611 812889 837837 891891 908523
960687 999999 1024947 1054053 1072071 1073709 1095633 1108107
1145529 1162161 1198197 1224531 1270269 1307691 1324323 1378377
 
runtime 0.147 s
3492 SumOfDivs 8918 CountOfDivs 18 isZk FALSE
3492 : 2^2*3^2*97
14184 SumOfDivs 38610 CountOfDivs 24 isZk FALSE
14184 : 2^3*3^2*197
58896 SumOfDivs 165230 CountOfDivs 30 isZk FALSE
58896 : 2^4*3^2*409
236448 SumOfDivs 673218 CountOfDivs 36 isZk FALSE
236448 : 2^5*3^2*821
954432 SumOfDivs 2737358 CountOfDivs 42 isZk FALSE
954432 : 2^6*3^2*1657
2549700 SumOfDivs 7994714 CountOfDivs 54 isZk FALSE
2549700 : 2^2*3^2*5^2*2833
10884600 SumOfDivs 36560160 CountOfDivs 72 isZk FALSE
10884600 : 2^3*3^2*5^2*6047
runtime 0.087 s
Real time: 3.738 s CPU share: 99.54 %
</pre>
NEW: Much faster: tested count of odd zumkeller numbers ti 1,000,000,000
<pre>count of odd zumkeller numbers up to 1,000,000,000
n count count/ time
prechecked
10000000 20637 96.860 % 2.839 s
20000000 41463 96.698 % 7.519 s
30000000 62002 96.637 % 13.391 s
40000000 82513 96.474 % 20.381 s
50000000 103001 96.351 % 28.329 s
60000000 123482 96.283 % 37.077 s
70000000 143933 96.232 % 46.573 s
80000000 164412 96.202 % 56.877 s
90000000 184816 96.165 % 67.944 s
100000000 205283 96.152 % 79.329 s
150000000 307454 95.956 % 148.857 s
200000000 409569 95.835 % 239.997 s
250000000 511807 95.796 % 344.792 s
300000000 613721 95.792 % 478.399 s
400000000 817456 95.743 % 840.497 s
500000000 1021438 95.720 % 1291.123 s
600000000 1225716 95.708 % 1820.230 s
700000000 1430227 95.683 % 2461.841 s
800000000 1634217 95.625 % 3263.611 s
900000000 1838186 95.569 % 4161.572 s
1000000000 2042196 95.526 % 5134.790 s
2042196 999999999 pre checked 1950822
</pre>
Tested odd zumkeller numbers up to 500,000,000 aka 5*10^8 , which takes 14h <BR>
'''All 205283 odd abundant numbers less than 10^8 that have even abundance are Zumkeller numbers. - T. D. Noe, Nov 14 2010'''<BR>
And yes there was no odd zumkeller with odd abundance->last prime factor must have a even power >0 2,4,6...
<pre> 1 h5m33 ->138978315 runtime 3933.063 s
+12 h ->482567085
+13 h ->501864363 stopped
count;number;SumOfDivs;CountofDivs;number : prime decomposition
10159 4999995; 12257280; 128 ; 4999995 : 3^3*5*7*11*13*37
10160 5000625; 10396672; 60 ; 5000625 : 3^2*5^4*7*127
 
20637 9999825; 20570112; 96 ; 9999825 : 3*5^2*11*17*23*31
20638 10000305; 20217600; 48 ; 10000305 : 3^2*5*7*53*599
 
41463 19999875; 40135680; 64 ; 19999875 : 3*5^3*7*19*401
41464 20000925; 45372096; 120 ; 20000925 : 3^4*5^2*7*17*83
 
62002 29999475; 66852864; 144 ; 29999475 : 3^2*5^2*11*17*23*31
62003 30000915; 62208000; 64 ; 30000915 : 3^3*5*7*53*599
 
82513 39999645; 82697472; 48 ; 39999645 : 3^2*5*7*23*5521
82514 40000275; 82985760; 72 ; 40000275 : 3^2*5^2*7*109*233
 
103001 49999635; 104884416; 48 ; 49999635 : 3^2*5*7*17*9337
103002 50000895; 102735360; 48 ; 50000895 : 3^5*5*7*5879
 
205283 99999375; 200935680; 80 ; 99999375 : 3*5^4*7*19*401 //205283 odd abundant numbers less than 10^8
205284 100000845; 217728000; 128 ; 100000845 : 3^3*5*7*29*41*89
 
307454 149999535; 307841040; 72 ; 149999535 : 3^2*5*7^2*59*1153
307455 150000165; 306748416; 48 ; 150000165 : 3^2*5*7*31*15361
 
409569 199999305; 400443264; 48 ; 199999305 : 3^2*5*11*17*23767
409570 200000115; 403269984; 36 ; 200000115 : 3^2*5*7^2*90703
 
511807 249999435; 521314560; 48 ; 249999435 : 3^2*5*7*19*41771
511808 250000065; 506782848; 48 ; 250000065 : 3^2*5*7*43*18457
 
613721 299998755; 609523200; 32 ; 299998755 : 3^3*5*7*317459
613722 300000645; 611696640; 64 ; 300000645 : 3^3*5*7*523*607
 
Start 1 at 1
715573 349998705; 742072320; 64 ; 349998705 : 3^3*5*7*23*16103
Count of zumkeller numbers up to 1000000
715574 350000595; 717044064; 40 ; 350000595 : 3^4*5*7*123457
1000000 tested found 229026 ratio 0.2290258
Count of zumkeller numbers up to 2000000
2000000 tested found 457658 ratio 0.2288289
Count of zumkeller numbers up to 3000000
3000000 tested found 686048 ratio 0.2286826
Count of zumkeller numbers up to 4000000
4000000 tested found 914806 ratio 0.2287014
Count of zumkeller numbers up to 5000000
5000000 tested found 1143521 ratio 0.2287042
Count of zumkeller numbers up to 6000000
6000000 tested found 1372208 ratio 0.2287013
Count of zumkeller numbers up to 7000000
7000000 tested found 1600977 ratio 0.2287110
Count of zumkeller numbers up to 8000000
8000000 tested found 1829932 ratio 0.2287415
Count of zumkeller numbers up to 9000000
9000000 tested found 2058883 ratio 0.2287648
Count of zumkeller numbers up to 10000000
10000000 tested found 2287889 ratio 0.2287889
runtime 1.268 s
//zumkeller number with highest recursion count til 1e11
Count of recursion 59,641,327 for 8,996,229,720
8996229720 : 96 : 2^3*3^2*5*2237*11171_SoD_29253435120<
14626717560 = 36+45+60+72+90+120+180+360+201330+804312+805320+2010780+4021560+1124528715+4498114860+8996229720 = 14626717560
runtime 7.068 s // at home 9.5s
 
Real time: 8.689 s CPU share: 98.74 %
817456 399998865; 808206336; 64 ; 399998865 : 3*5*7*17*23*9743
817457 400000293; 803312640; 96 ; 400000293 : 3^2*7*11*17*19*1787
 
//at home til 1e11 with 85 numbers with recursion count > 1e8
919451 449999235; 922184640; 48 ; 449999235 : 3^2*5*7*29*49261
9900000000 tested found 2262797501 ratio 0.2285654 recursion 10.479
919452 450000495; 943841280; 64 ; 450000495 : 3^3*5*7*31*15361
runtime 48.805 s
Count of zumkeller numbers up to 10000000000
rek_ -1 @ 9998443080 : 96 : 2^3*3^2*5*3041*9133_SoD_32509184760<
 
10000000000 tested found 2285655276 ratio 0.2285655 recursion 10.520
1021438 499999185; 1052101440; 72 ; 499999185 : 3^2*5*7^2*23*9859
runtime 28.976 s
1021439 500000445; 1027178880; 48 ; 500000445 : 3^5*5*7*58789
 
real 40m7,478s user 40m7,039s sys 0m0,057s
ODD Zumkeller Index;CoD Count of Divisors;Average CoD;Zumkeller number
only 4 til 4,512,612,672
1; 16; 16.0000;945 : 3^3*5*7
out_1e10.txt:104: rek_ -1 @ 584818848 : 72 : 2^5*3^2*1423*1427_SoD_1665413568<
2; 18; 18.0000;1575 : 3^2*5^2*7
out_1e10.txt:105: rek_ -1 @ 589754016 : 72 : 2^5*3^2*1429*1433_SoD_1679457780<
4; 20; 19.0000;2835 : 3^4*5*7
out_1e10.txt:174: rek_ -1 @ 1956249450 : 72 : 2*3^2*5^2*2083*2087_SoD_5260832928<
5; 24; 24.0000;3465 : 3^2*5*7*11
out_1e10.txt:291: rek_ -1 @ 4512612672 : 84 : 2^6*3^2*2797*2801_SoD_12943833396<
24; 32; 24.4211;10395 : 3^3*5*7*11
36; 36; 27.5000;17325 : 3^2*5^2*7*11
69; 40; 30.4242;31185 : 3^4*5*7*11
101; 48; 33.3125;45045 : 3^2*5*7*11*13
246; 54; 37.7931;121275 : 3^2*5^2*7^2*11
272; 64; 41.1538;135135 : 3^3*5*7*11*13
439; 72; 43.2335;225225 : 3^2*5^2*7*11*13
814; 80; 45.8027;405405 : 3^4*5*7*11*13
1366; 96; 49.0688;675675 : 3^3*5^2*7*11*13
3126; 108; 53.1364;1576575 : 3^2*5^2*7^2*11*13
4025; 120; 55.8843;2027025 : 3^4*5^2*7*11*13
4573; 128; 56.6752;2297295 : 3^3*5*7*11*13*17
7715; 144; 58.4978;3828825 : 3^2*5^2*7*11*13*17
14116; 160; 61.1239;6891885 : 3^4*5*7*11*13*17
23733; 192; 63.7696;11486475 : 3^3*5^2*7*11*13*17
55414; 216; 67.8331;26801775 : 3^2*5^2*7^2*11*13*17
71154; 240; 70.7454;34459425 : 3^4*5^2*7*11*13*17
89984; 256; 72.0990;43648605 : 3^3*5*7*11*13*17*19
149543; 288; 74.2782;72747675 : 3^2*5^2*7*11*13*17*19
268601; 320; 77.3901;130945815 : 3^4*5*7*11*13*17*19
446838; 384; 80.4003;218243025 : 3^3*5^2*7*11*13*17*19
last 501864363
1025232 84.3602;
1025232 80.7680;501864363 : 3^3*7*11*13*31*599
CntOfDivs|Count | last occurence
16 1 945
18 2 2205
20 1 2835
24 37 32445
28 1 25515
30 5 108045
32 44011 501862095
36 47777 501859575
40 16114 501848865
42 6 5294205
44 1 2066715
48 197324 501856425
50 4 972405
52 1 18600435
54 2795 499226175
56 2254 501650415
60 11478 501809175
64 154291 501863985
66 4 19190925
70 8 47647845
72 102440 501846975
78 4 172718325
80 34227 501843195
84 1892 501788925
88 71 498078315
90 1987 501185475
96 211623 501863175
98 4 428830605
100 670 500833125
104 8 496897335
108 13834 501858225
110 3 479773125
112 4445 501803505
120 20477 501833475
126 310 501701445
128 67263 501864363
132 32 485678025
140 138 500731875
144 48901 501862725
150 136 500788575
160 11220 501808125
162 454 501511725
168 1299 501570225
176 4 456744015
180 1599 501780825
192 19903 501838155
200 173 501744375
210 6 481340475
216 2097 501752475
224 274 501854535
240 1368 501860205
252 42 499200975
256 1163 501756255
270 21 495685575
280 1 456080625
288 871 501666165
300 2 463876875
320 92 499926735
324 9 471395925
336 6 485269785
360 13 500675175
384 32 498513015
</pre>
 
=={{header|Perl}}==
{{libheader|ntheory}}
<langsyntaxhighlight lang="perl">use strict;
use warnings;
use feature 'say';
Line 3,668 ⟶ 3,982:
$n = 0; $z = '';
$z .= do { $n < 40 ? (!!($_%2 and $_%5) and is_Zumkeller($_) and ++$n and "$_ ") : last } for 1 .. Inf;
in_columns(10, $z);</langsyntaxhighlight>
 
{{out}}
Line 3,698 ⟶ 4,012:
=={{header|Phix}}==
{{trans|Go}}
<!--<lang Phix>(phixonline)-->
<syntaxhighlight lang="Phix">
<span style="color: #008080;">function</span> <span style="color: #000000;">isPartSum</span><span style="color: #0000FF;">(</span><span style="color: #004080;">sequence</span> <span style="color: #000000;">f</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">integer</span> <span style="color: #000000;">l</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">t</span><span style="color: #0000FF;">)</span>
with javascript_semantics
<span style="color: #008080;">if</span> <span style="color: #000000;">t</span><span style="color: #0000FF;">=</span><span style="color: #000000;">0</span> <span style="color: #008080;">then</span> <span style="color: #008080;">return</span> <span style="color: #004600;">true</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
function isPartSum(sequence f, integer l, t)
<span style="color: #008080;">if</span> <span style="color: #000000;">l</span><span style="color: #0000FF;">=</span><span style="color: #000000;">0</span> <span style="color: #008080;">then</span> <span style="color: #008080;">return</span> <span style="color: #004600;">false</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
if t=0 then return true end if
<span style="color: #004080;">integer</span> <span style="color: #000000;">last</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">f</span><span style="color: #0000FF;">[</span><span style="color: #000000;">l</span><span style="color: #0000FF;">]</span>
if l=0 then return false end if
<span style="color: #008080;">return</span> <span style="color: #0000FF;">(</span><span style="color: #000000;">t</span><span style="color: #0000FF;">>=</span><span style="color: #000000;">last</span> <span style="color: #008080;">and</span> <span style="color: #000000;">isPartSum</span><span style="color: #0000FF;">(</span><span style="color: #000000;">f</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">l</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">t</span><span style="color: #0000FF;">-</span><span style="color: #000000;">last</span><span style="color: #0000FF;">))</span>
integer last = f[l]
<span style="color: #008080;">or</span> <span style="color: #000000;">isPartSum</span><span style="color: #0000FF;">(</span><span style="color: #000000;">f</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">l</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">t</span><span style="color: #0000FF;">)</span>
return (t>=last and isPartSum(f, l-1, t-last))
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
or isPartSum(f, l-1, t)
end function
<span style="color: #008080;">function</span> <span style="color: #000000;">isZumkeller</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">f</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;">1</span><span style="color: #0000FF;">)</span>
function isZumkeller(integer n)
<span style="color: #004080;">integer</span> <span style="color: #000000;">t</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">sum</span><span style="color: #0000FF;">(</span><span style="color: #000000;">f</span><span style="color: #0000FF;">)</span>
sequence f = factors(n,1)
<span style="color: #000080;font-style:italic;">-- an odd sum cannot be split into two equal sums</span>
integer t = sum(f)
<span style="color: #008080;">if</span> <span style="color: #7060A8;">remainder</span><span style="color: #0000FF;">(</span><span style="color: #000000;">t</span><span style="color: #0000FF;">,</span><span style="color: #000000;">2</span><span style="color: #0000FF;">)=</span><span style="color: #000000;">1</span> <span style="color: #008080;">then</span> <span style="color: #008080;">return</span> <span style="color: #004600;">false</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
-- an odd sum cannot be split into two equal sums
<span style="color: #000080;font-style:italic;">-- if n is odd use 'abundant odd number' optimization</span>
if odd(t) then return false end if
<span style="color: #008080;">if</span> <span style="color: #7060A8;">remainder</span><span style="color: #0000FF;">(</span><span style="color: #000000;">n</span><span style="color: #0000FF;">,</span><span style="color: #000000;">2</span><span style="color: #0000FF;">)=</span><span style="color: #000000;">1</span> <span style="color: #008080;">then</span>
-- if n is odd use 'abundant odd number' optimization
<span style="color: #004080;">integer</span> <span style="color: #000000;">abundance</span> <span style="color: #0000FF;">:=</span> <span style="color: #000000;">t</span> <span style="color: #0000FF;">-</span> <span style="color: #000000;">2</span><span style="color: #0000FF;">*</span><span style="color: #000000;">n</span>
if odd(n) then
<span style="color: #008080;">return</span> <span style="color: #000000;">abundance</span><span style="color: #0000FF;">></span><span style="color: #000000;">0</span> <span style="color: #008080;">and</span> <span style="color: #7060A8;">remainder</span><span style="color: #0000FF;">(</span><span style="color: #000000;">abundance</span><span style="color: #0000FF;">,</span><span style="color: #000000;">2</span><span style="color: #0000FF;">)=</span><span style="color: #000000;">0</span>
integer abundance := t - 2*n
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
return abundance>0 and even(abundance)
<span style="color: #000080;font-style:italic;">-- if n and t both even check for any partition of t/2</span>
end if
<span style="color: #008080;">return</span> <span style="color: #000000;">isPartSum</span><span style="color: #0000FF;">(</span><span style="color: #000000;">f</span><span style="color: #0000FF;">,</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">f</span><span style="color: #0000FF;">),</span> <span style="color: #000000;">t</span><span style="color: #0000FF;">/</span><span style="color: #000000;">2</span><span style="color: #0000FF;">)</span>
-- if n and t both even check for any partition of t/2
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
return isPartSum(f, length(f), t/2)
end function
<span style="color: #004080;">sequence</span> <span style="color: #000000;">tests</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{{</span><span style="color: #000000;">220</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">20</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%3d "</span><span style="color: #0000FF;">},</span>
<span style="color: #0000FF;">{</span><span style="color: #000000;">40</span><span style="color: #0000FF;">,</span><span style="color: #000000;">2</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">10</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%5d "</span><span style="color: #0000FF;">},</span>
sequence tests = {{220,1,0,20,"%3d %n"},
<span style="color: #0000FF;">{</span><span style="color: #000000;">40</span><span style="color: #0000FF;">,</span><span style="color: #000000;">2</span><span style="color: #0000FF;">,</span><span style="color: #000000;">5</span><span style="color: #0000FF;">,</span><span style="color: #000000;">8</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%7d "</span><span style="color: #0000FF;">}}</span>
{40,2,0,10,"%5d %n"},
<span style="color: #004080;">integer</span> <span style="color: #000000;">lim</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">step</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">rem</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">cr</span><span style="color: #0000FF;">;</span> <span style="color: #004080;">string</span> <span style="color: #000000;">fmt</span>
{40,2,5,8,"%7d %n"}}
<span style="color: #008080;">for</span> <span style="color: #000000;">t</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">tests</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span>
integer lim, step, rem, cr; string fmt
<span style="color: #0000FF;">{</span><span style="color: #000000;">lim</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">step</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">rem</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">cr</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">fmt</span><span style="color: #0000FF;">}</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">tests</span><span style="color: #0000FF;">[</span><span style="color: #000000;">t</span><span style="color: #0000FF;">]</span>
for t=1 to length(tests) do
<span style="color: #004080;">string</span> <span style="color: #000000;">odd</span> <span style="color: #0000FF;">=</span> <span style="color: #008080;">iff</span><span style="color: #0000FF;">(</span><span style="color: #000000;">step</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span><span style="color: #0000FF;">?</span><span style="color: #008000;">""</span><span style="color: #0000FF;">:</span><span style="color: #008000;">"odd "</span><span style="color: #0000FF;">),</span>
{lim, step, rem, cr, fmt} = tests[t]
<span style="color: #000000;">wch</span> <span style="color: #0000FF;">=</span> <span style="color: #008080;">iff</span><span style="color: #0000FF;">(</span><span style="color: #000000;">rem</span><span style="color: #0000FF;">=</span><span style="color: #000000;">0</span><span style="color: #0000FF;">?</span><span style="color: #008000;">""</span><span style="color: #0000FF;">:</span><span style="color: #008000;">"which don't end in 5 "</span><span style="color: #0000FF;">)</span>
string o = iff(step=1?"":"odd "),
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"The first %d %sZumkeller numbers %sare:\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">lim</span><span style="color: #0000FF;">,</span><span style="color: #000000;">odd</span><span style="color: #0000FF;">,</span><span style="color: #000000;">wch</span><span style="color: #0000FF;">})</span>
w = iff(rem=0?"":"which don't end in 5 ")
<span style="color: #004080;">integer</span> <span style="color: #000000;">i</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">step</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">count</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0</span>
printf(1,"The first %d %sZumkeller numbers %sare:\n",{lim,o,w})
<span style="color: #008080;">while</span> <span style="color: #000000;">count</span><span style="color: #0000FF;"><</span><span style="color: #000000;">lim</span> <span style="color: #008080;">do</span>
integer i = step+1, count = 0
<span style="color: #008080;">if</span> <span style="color: #0000FF;">(</span><span style="color: #000000;">rem</span><span style="color: #0000FF;">=</span><span style="color: #000000;">0</span> <span style="color: #008080;">or</span> <span style="color: #7060A8;">remainder</span><span style="color: #0000FF;">(</span><span style="color: #000000;">i</span><span style="color: #0000FF;">,</span><span style="color: #000000;">10</span><span style="color: #0000FF;">)!=</span><span style="color: #000000;">rem</span><span style="color: #0000FF;">)</span>
while count<lim do
<span style="color: #008080;">and</span> <span style="color: #000000;">isZumkeller</span><span style="color: #0000FF;">(</span><span style="color: #000000;">i</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">then</span>
if (rem=0 or remainder(i,10)!=rem)
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">fmt</span><span style="color: #0000FF;">,</span><span style="color: #000000;">i</span><span style="color: #0000FF;">)</span>
and isZumkeller(i) then
<span style="color: #000000;">count</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span>
count += 1
<span style="color: #008080;">if</span> <span style="color: #7060A8;">remainder</span><span style="color: #0000FF;">(</span><span style="color: #000000;">count</span><span style="color: #0000FF;">,</span><span style="color: #000000;">cr</span><span style="color: #0000FF;">)=</span><span style="color: #000000;">0</span> <span style="color: #008080;">then</span> <span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\n"</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
printf(1,fmt,{i,remainder(count,cr)=0})
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
end if
<span style="color: #000000;">i</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">step</span>
i += step
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
end while
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\n"</span><span style="color: #0000FF;">)</span>
printf(1,"\n")
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
end for
<!--</lang>-->
</syntaxhighlight>
{{out}}
<pre>
Line 3,779 ⟶ 4,094:
 
=={{header|PicoLisp}}==
<langsyntaxhighlight lang="PicoLisp">(de propdiv (N)
(make
(for I N
Line 3,830 ⟶ 4,145:
(and
(=0 (% C 8))
(prinl) ) ) )</langsyntaxhighlight>
{{out}}
<pre>
Line 3,861 ⟶ 4,176:
===Procedural===
Modified from a footnote at OEIS A083207 (see reference in problem text) by Charles R Greathouse IV.
<langsyntaxhighlight lang="python">from sympy import divisors
 
from sympy.combinatorics.subsets import Subset
Line 3,893 ⟶ 4,208:
print("\n\n40 odd Zumkeller numbers:")
printZumkellers(40, True)
</langsyntaxhighlight>{{out}}
<pre>
220 Zumkeller numbers:
Line 3,931 ⟶ 4,246:
Relying on the standard Python libraries, as an alternative to importing SymPy:
 
<langsyntaxhighlight lang="python">'''Zumkeller numbers'''
 
from itertools import (
Line 4,133 ⟶ 4,448:
# MAIN ---
if __name__ == '__main__':
main()</langsyntaxhighlight>
{{Out}}
<pre>First 220 Zumkeller numbers:
Line 4,170 ⟶ 4,485:
{{trans|Zkl}}
 
<langsyntaxhighlight lang="racket">#lang racket
 
(require math/number-theory)
Line 4,210 ⟶ 4,525:
(newline)
(tabulate "First 40 odd Zumkeller numbers not ending in 5:"
(first-n-matching-naturals 40 (λ (n) (and (odd? n) (not (= 5 (modulo n 10))) (zum? n)))))</langsyntaxhighlight>
 
{{out}}
Line 4,233 ⟶ 4,548:
=={{header|Raku}}==
(formerly Perl 6)
{{libheader|ntheory}}
{{works with|Rakudo|2019.07.1}}
<syntaxhighlight lang="raku" line>use ntheory:from<Perl5> <factor is_prime>;
 
<lang perl6>use ntheory:from<Perl5> <factor is_prime>;
 
sub zumkeller ($range) {
$range.grep: -> $maybe {
next if $maybe < 3 or $maybe.&is_prime;
nextmy if@divisors = $maybe.&is_primefactor.combinations».reduce( &[×] ).unique.reverse;
next unless [and] @divisors > 2, @divisors %% 2, (my $sum = @divisors.sum) %% 2, ($sum /= 2) ≥ $maybe;
my @divisors = $maybe.&factor.combinations».reduce( &[*] ).unique.reverse;
next unless [&&] +@divisors > 2, +@divisors %% 2, (my $sum = sum @divisors) %% 2, ($sum /= 2) >= $maybe;
my $zumkeller = False;
if $maybe % 2 {
$zumkeller = True
} else {
TEST: loop (my $c =for 1; $c <..^ @divisors /2 2;-> ++$c) {
@divisors.combinations($c).map: -> $d {
next if (sum $d).sum != $sum;
$zumkeller = True and last TEST;
}
}
Line 4,262 ⟶ 4,575:
 
put "\nFirst 40 odd Zumkeller numbers:\n" ~
zumkeller((^Inf).map: * *× 2 + 1)[^40].rotor(10)».fmt('%7d').join: "\n";
 
# Stretch. Slow to calculate. (minutes)
put "\nFirst 40 odd Zumkeller numbers not divisible by 5:\n" ~
zumkeller(flat (^Inf).map: {my \p = 10 * $_; p+1, p+3, p+7, p+9} )[^40].rotor(10)».fmt('%7d').join: "\n";</langsyntaxhighlight>
{{out}}
<pre>First 220 Zumkeller numbers:
Line 4,295 ⟶ 4,608:
=={{header|REXX}}==
The construction of the partitions were created in the order in which the most likely partitions would match.
<langsyntaxhighlight lang="rexx">/*REXX pgm finds & shows Zumkeller numbers: 1st N; 1st odd M; 1st odd V not ending in 5.*/
parse arg n m v . /*obtain optional arguments from the CL*/
if n=='' | n=="," then n= 220 /*Not specified? Then use the default.*/
Line 4,385 ⟶ 4,698:
if p1==p2 then return 1 /*Partition sums equal? Then X is Zum.*/
end /*part*/
return 0 /*no partition sum passed. X isn't Zum*/</langsyntaxhighlight>
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>
Line 4,408 ⟶ 4,721:
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
load "stdlib.ring"
 
Line 4,573 ⟶ 4,886:
last -= 1
end
</syntaxhighlight>
</lang>
Output:
<pre>
Line 4,599 ⟶ 4,912:
 
=={{header|Ruby}}==
<langsyntaxhighlight lang="ruby">class Integer
def divisors
Line 4,635 ⟶ 4,948:
puts "\n#{n=40} odd Zumkeller numbers not ending with 5:"
p_enum 1.step(by: 2).lazy.select{|x| x % 5 > 0 && x.zumkeller?}.take(n)
</syntaxhighlight>
</lang>
{{out}}
<pre>220 Zumkeller numbers:
Line 4,669 ⟶ 4,982:
 
=={{header|Rust}}==
<langsyntaxhighlight lang="rust">
use std::convert::TryInto;
 
Line 4,754 ⟶ 5,067:
}
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 4,772 ⟶ 5,085:
 
=={{header|Sidef}}==
<langsyntaxhighlight lang="ruby">func is_Zumkeller(n) {
 
return false if n.is_prime
Line 4,805 ⟶ 5,118:
 
say "\nFirst 40 odd Zumkeller numbers not divisible by 5: "
say (1..Inf `by` 2 -> lazy.grep { _ % 5 != 0 }.grep(is_Zumkeller).first(40).join(' '))</langsyntaxhighlight>
{{out}}
<pre>
Line 4,819 ⟶ 5,132:
 
=={{header|Standard ML}}==
<langsyntaxhighlight lang="Standard ML">
exception Found of string ;
 
Line 4,872 ⟶ 5,185:
 
end;
</syntaxhighlight>
</lang>
call loop and output - interpreter
<langsyntaxhighlight lang="Standard ML">
- val Zumkellerlist = fn step => fn no5 =>
let
Line 4,907 ⟶ 5,220:
742203, 783783, 793611, 812889, 837837, 891891, 908523, 960687, 999999, 1024947, 1054053, 1072071, 1073709, 1095633, 1108107, 1145529,
1162161, 1198197, 1224531, 1270269, 1307691, 1324323, 1378377
</syntaxhighlight>
</lang>
 
=={{header|Swift}}==
Line 4,913 ⟶ 5,226:
{{trans|Go}}
 
<langsyntaxhighlight lang="swift">import Foundation
 
extension BinaryInteger {
Line 4,973 ⟶ 5,286:
print("First 220 zumkeller numbers are \(Array(zums.prefix(220)))")
print("First 40 odd zumkeller numbers are \(Array(oddZums.prefix(40)))")
print("First 40 odd zumkeller numbers that don't end in a 5 are: \(Array(oddZumsWithout5.prefix(40)))")</langsyntaxhighlight>
 
{{out}}
Line 4,980 ⟶ 5,293:
First 40 odd zumkeller numbers are: [945, 1575, 2205, 2835, 3465, 4095, 4725, 5355, 5775, 5985, 6435, 6615, 6825, 7245, 7425, 7875, 8085, 8415, 8505, 8925, 9135, 9555, 9765, 10395, 11655, 12285, 12705, 12915, 13545, 14175, 14805, 15015, 15435, 16065, 16695, 17325, 17955, 18585, 19215, 19305]
First 40 odd zumkeller numbers that don't end in a 5 are: [81081, 153153, 171171, 189189, 207207, 223839, 243243, 261261, 279279, 297297, 351351, 459459, 513513, 567567, 621621, 671517, 729729, 742203, 783783, 793611, 812889, 837837, 891891, 908523, 960687, 999999, 1024947, 1054053, 1072071, 1073709, 1095633, 1108107, 1145529, 1162161, 1198197, 1224531, 1270269, 1307691, 1324323, 1378377]</pre>
 
=={{header|Typescript}}==
{{trans|Go}}
<syntaxhighlight lang="typescript">
/**
* return an array of divisors of a number(n)
* @params {number} n The number to find divisors from
* @return {number[]} divisors of n
*/
function getDivisors(n: number): number[] {
//initialize divisors array
let divisors: number[] = [1, n]
//loop through all numbers from 2 to sqrt(n)
for (let i = 2; i*i <= n; i++) {
// if i is a divisor of n
if (n % i == 0) {
// add i to divisors array
divisors.push(i);
// quotient of n/i is also a divisor of n
let j = n/i;
// if quotient is not equal to i
if (i != j) {
// add quotient to divisors array
divisors.push(j);
}
}
}
 
return divisors
}
/**
* return sum of an array of number
* @param {number[]} arr The array we need to sum
* @return {number} sum of arr
*/
function getSum(arr: number[]): number {
return arr.reduce((prev, curr) => prev + curr, 0)
}
/**
* check if there is a subset of divisors which sums to a specific number
* @param {number[]} divs The array of divisors
* @param {number} sum The number to check if there's a subset of divisors which sums to it
* @return {boolean} true if sum is 0, false if divisors length is 0
*/
function isPartSum(divs: number[], sum: number): boolean {
// if sum is 0, the partition is sum up to the number(sum)
if (sum == 0) return true;
//get length of divisors array
let len = divs.length;
// if divisors array is empty the partion doesnt not sum up to the number(sum)
if (len == 0) return false;
//get last element of divisors array
let last = divs[len - 1];
//create a copy of divisors array without the last element
const newDivs = [...divs];
newDivs.pop();
// if last element is greater than sum
if (last > sum) {
// recursively check if there's a subset of divisors which sums to sum using the new divisors array
return isPartSum(newDivs, sum);
}
// recursively check if there's a subset of divisors which sums to sum using the new divisors array
// or if there's a subset of divisors which sums to sum - last using the new divisors array
return isPartSum(newDivs, sum) || isPartSum(newDivs, sum - last);
}
/**
* check if a number is a Zumkeller number
* @param {number} n The number to check if it's a Zumkeller number
* @returns {boolean} true if n is a Zumkeller number, false otherwise
*/
function isZumkeller(n: number): boolean {
// get divisors of n
let divs = getDivisors(n);
// get sum of divisors of n
let sum = getSum(divs);
// if sum is odd can't be split into two partitions with equal sums
if (sum % 2 == 1) return false;
// if n is odd use 'abundant odd number' optimization
if (n % 2 == 1) {
let abundance = sum - 2 * n
return abundance > 0 && abundance%2 == 0;
}
// if n and sum are both even check if there's a partition which totals sum / 2
return isPartSum(divs, sum/2);
}
/**
* find x zumkeller numbers
* @param {number} x The number of zumkeller numbers to find
* @returns {number[]} array of x zumkeller numbers
*/
function getXZumkelers(x: number): number[] {
let zumkellers: number[] = [];
let i = 2;
let count= 0;
while (count < x) {
if (isZumkeller(i)) {
zumkellers.push(i);
count++;
}
i++;
}
 
return zumkellers;
}
 
/**
* find x Odd Zumkeller numbers
* @param {number} x The number of odd zumkeller numbers to find
* @returns {number[]} array of x odd zumkeller numbers
*/
function getXOddZumkelers(x: number): number[] {
let oddZumkellers: number[] = [];
let i = 3;
let count = 0;
while (count < x) {
if (isZumkeller(i)) {
oddZumkellers.push(i);
count++;
}
i += 2;
}
 
return oddZumkellers;
}
 
/**
* find x odd zumkeller number which are not end with 5
* @param {number} x The number of odd zumkeller numbers to find
* @returns {number[]} array of x odd zumkeller numbers
*/
function getXOddZumkellersNotEndWith5(x: number): number[] {
let oddZumkellers: number[] = [];
let i = 3;
let count = 0;
while (count < x) {
if (isZumkeller(i) && i % 10 != 5) {
oddZumkellers.push(i);
count++;
}
i += 2;
}
 
return oddZumkellers;
}
 
//get the first 220 zumkeller numbers
console.log("First 220 Zumkeller numbers: ", getXZumkelers(220));
 
//get the first 40 odd zumkeller numbers
console.log("First 40 odd Zumkeller numbers: ", getXOddZumkelers(40));
 
//get the first 40 odd zumkeller numbers which are not end with 5
console.log("First 40 odd Zumkeller numbers which are not end with 5: ", getXOddZumkellersNotEndWith5(40));
</syntaxhighlight>
 
{{out}}
<pre>
"First 220 Zumkeller numbers: ", [6, 12, 20, 24, 28, 30, 40, 42, 48, 54, 56, 60, 66, 70, 78, 80, 84, 88, 90, 96, 102, 104, 108, 112, 114, 120, 126, 132, 138, 140, 150, 156, 160, 168, 174, 176, 180, 186, 192, 198, 204, 208, 210, 216, 220, 222, 224, 228, 234, 240, 246, 252, 258, 260, 264, 270, 272, 276, 280, 282, 294, 300, 304, 306, 308, 312, 318, 320, 330, 336, 340, 342, 348, 350, 352, 354, 360, 364, 366, 368, 372, 378, 380, 384, 390, 396, 402, 408, 414, 416, 420, 426, 432, 438, 440, 444, 448, 456, 460, 462, 464, 468, 474, 476, 480, 486, 490, 492, 496, 498, 500, 504, 510, 516, 520, 522, 528, 532, 534, 540, 544, 546, 550, 552, 558, 560, 564, 570, 572, 580, 582, 588, 594, 600, 606, 608, 612, 616, 618, 620, 624, 630, 636, 640, 642, 644, 650, 654, 660, 666, 672, 678, 680, 684, 690, 696, 700, 702, 704, 708, 714, 720, 726, 728, 732, 736, 740, 744, 750, 756, 760, 762, 768, 770, 780, 786, 792, 798, 804, 810, 812, 816, 820, 822, 828, 832, 834, 836, 840, 852, 858, 860, 864, 868, 870, 876, 880, 888, 894, 896, 906, 910, 912, 918, 920, 924, 928, 930, 936, 940, 942, 945, 948, 952, 960, 966, 972, 978, 980, 984]
"First 40 odd Zumkeller numbers: ", [945, 1575, 2205, 2835, 3465, 4095, 4725, 5355, 5775, 5985, 6435, 6615, 6825, 7245, 7425, 7875, 8085, 8415, 8505, 8925, 9135, 9555, 9765, 10395, 11655, 12285, 12705, 12915, 13545, 14175, 14805, 15015, 15435, 16065, 16695, 17325, 17955, 18585, 19215, 19305]
"First 40 odd Zumkeller numbers which are not end with 5: ", [81081, 153153, 171171, 189189, 207207, 223839, 243243, 261261, 279279, 297297, 351351, 459459, 513513, 567567, 621621, 671517, 729729, 742203, 783783, 793611, 812889, 837837, 891891, 908523, 960687, 999999, 1024947, 1054053, 1072071, 1073709, 1095633, 1108107, 1145529, 1162161, 1198197, 1224531, 1270269, 1307691, 1324323, 1378377]
</pre>
 
=={{header|Visual Basic .NET}}==
{{trans|C#}}
<langsyntaxhighlight lang="vbnet">Module Module1
Function GetDivisors(n As Integer) As List(Of Integer)
Dim divs As New List(Of Integer) From {
Line 5,082 ⟶ 5,561:
End While
End Sub
End Module</langsyntaxhighlight>
{{out}}
<pre>The first 220 Zumkeller numbers are:
Line 5,109 ⟶ 5,588:
960687 999999 1024947 1054053 1072071 1073709 1095633 1108107
1145529 1162161 1198197 1224531 1270269 1307691 1324323 1378377</pre>
 
=={{header|V (Vlang)}}==
{{trans|Go}}
<syntaxhighlight lang="v (vlang)">fn get_divisors(n int) []int {
mut divs := [1, n]
for i := 2; i*i <= n; i++ {
if n%i == 0 {
j := n / i
divs << i
if i != j {
divs << j
}
}
}
return divs
}
fn sum(divs []int) int {
mut sum := 0
for div in divs {
sum += div
}
return sum
}
fn is_part_sum(d []int, sum int) bool {
mut divs := d.clone()
if sum == 0 {
return true
}
le := divs.len
if le == 0 {
return false
}
last := divs[le-1]
divs = divs[0 .. le-1]
if last > sum {
return is_part_sum(divs, sum)
}
return is_part_sum(divs, sum) || is_part_sum(divs, sum-last)
}
fn is_zumkeller(n int) bool {
divs := get_divisors(n)
s := sum(divs)
// if sum is odd can't be split into two partitions with equal sums
if s%2 == 1 {
return false
}
// if n is odd use 'abundant odd number' optimization
if n%2 == 1 {
abundance := s - 2*n
return abundance > 0 && abundance%2 == 0
}
// if n and sum are both even check if there's a partition which totals sum / 2
return is_part_sum(divs, s/2)
}
fn main() {
println("The first 220 Zumkeller numbers are:")
for i, count := 2, 0; count < 220; i++ {
if is_zumkeller(i) {
print("${i:3} ")
count++
if count%20 == 0 {
println('')
}
}
}
println("\nThe first 40 odd Zumkeller numbers are:")
for i, count := 3, 0; count < 40; i += 2 {
if is_zumkeller(i) {
print("${i:5} ")
count++
if count%10 == 0 {
println('')
}
}
}
println("\nThe first 40 odd Zumkeller numbers which don't end in 5 are:")
for i, count := 3, 0; count < 40; i += 2 {
if (i % 10 != 5) && is_zumkeller(i) {
print("${i:7} ")
count++
if count%8 == 0 {
println('')
}
}
}
println('')
}</syntaxhighlight>
 
{{out}}
<pre>
The first 220 Zumkeller numbers are:
6 12 20 24 28 30 40 42 48 54 56 60 66 70 78 80 84 88 90 96
102 104 108 112 114 120 126 132 138 140 150 156 160 168 174 176 180 186 192 198
204 208 210 216 220 222 224 228 234 240 246 252 258 260 264 270 272 276 280 282
294 300 304 306 308 312 318 320 330 336 340 342 348 350 352 354 360 364 366 368
372 378 380 384 390 396 402 408 414 416 420 426 432 438 440 444 448 456 460 462
464 468 474 476 480 486 490 492 496 498 500 504 510 516 520 522 528 532 534 540
544 546 550 552 558 560 564 570 572 580 582 588 594 600 606 608 612 616 618 620
624 630 636 640 642 644 650 654 660 666 672 678 680 684 690 696 700 702 704 708
714 720 726 728 732 736 740 744 750 756 760 762 768 770 780 786 792 798 804 810
812 816 820 822 828 832 834 836 840 852 858 860 864 868 870 876 880 888 894 896
906 910 912 918 920 924 928 930 936 940 942 945 948 952 960 966 972 978 980 984
 
The first 40 odd Zumkeller numbers are:
945 1575 2205 2835 3465 4095 4725 5355 5775 5985
6435 6615 6825 7245 7425 7875 8085 8415 8505 8925
9135 9555 9765 10395 11655 12285 12705 12915 13545 14175
14805 15015 15435 16065 16695 17325 17955 18585 19215 19305
 
The first 40 odd Zumkeller numbers which don't end in 5 are:
81081 153153 171171 189189 207207 223839 243243 261261
279279 297297 351351 459459 513513 567567 621621 671517
729729 742203 783783 793611 812889 837837 891891 908523
960687 999999 1024947 1054053 1072071 1073709 1095633 1108107
1145529 1162161 1198197 1224531 1270269 1307691 1324323 1378377
</pre>
 
=={{header|Wren}}==
Line 5,115 ⟶ 5,714:
{{libheader|Wren-fmt}}
I've reversed the order of the recursive calls in the last line of the ''isPartSum'' function which, as noted in the Phix entry, seems to make little difference to Go but (as one might have expected) speeds up this Wren script enormously. The first part is now near instant but was taking several minutes previously. Overall it's now only about 5.5 times slower than Go itself which is a good result for the Wren interpreter.
<langsyntaxhighlight ecmascriptlang="wren">import "./math" for Int, Nums
import "./fmt" for Fmt
import "io" for Stdout
 
Line 5,181 ⟶ 5,780:
i = i + 2
}
System.print()</langsyntaxhighlight>
 
{{out}}
Line 5,214 ⟶ 5,813:
=={{header|zkl}}==
{{trans|Julia}} {{trans|Go}}
<langsyntaxhighlight lang="zkl">fcn properDivs(n){ // does not include n
// if(n==1) return(T); // we con't care about this case
( pd:=[1..(n).toFloat().sqrt()].filter('wrap(x){ n%x==0 }) )
Line 5,237 ⟶ 5,836:
}
canSum(sum/2,ds) and n or Void.Skip // sum is even
}</langsyntaxhighlight>
<langsyntaxhighlight lang="zkl">println("First 220 Zumkeller numbers:");
zw:=[2..].tweak(isZumkellerW);
do(11){ zw.walk(20).pump(String,"%4d ".fmt).println() }
Line 5,248 ⟶ 5,847:
println("\nThe first 40 odd Zumkeller numbers which don't end in 5 are:");
zw:=[3..*, 2].tweak(fcn(n){ if(n%5) isZumkellerW(n) else Void.Skip });
do(5){ zw.walk(8).pump(String,"%7d ".fmt).println() }</langsyntaxhighlight>
{{out}}
<pre style="font-size:83%">
Line 5,277 ⟶ 5,876:
1145529 1162161 1198197 1224531 1270269 1307691 1324323 1378377
</pre>
[[Link title]]
1,983

edits