Calmo numbers: Difference between revisions
Content added Content deleted
(Created Nim solution.) |
No edit summary |
||
Line 392: | Line 392: | ||
957 [3, 11, 29, 33, 87, 319] [43, 439] |
957 [3, 11, 29, 33, 87, 319] [43, 439] |
||
</pre> |
</pre> |
||
=={{header|Delphi}}== |
|||
{{works with|Delphi|6.0}} |
|||
{{libheader|SysUtils,StdCtrls}} |
|||
<syntaxhighlight lang="Delphi"> |
|||
var Facts: TIntegerDynArray; |
|||
function IsCalmoNumber(N: integer): boolean; |
|||
{Test number to see if it a Calmo number} |
|||
var Inx,Sum: integer; |
|||
begin |
|||
Result:=False; |
|||
{Get all divisors} |
|||
GetAllDivisors(N,Facts); |
|||
{strip off 1 and N } |
|||
Facts:=Copy(Facts,1,High(Facts)-1); |
|||
if Length(Facts)<3 then exit; |
|||
{Must be at least three} |
|||
if (Length(Facts) mod 3)<>0 then exit; |
|||
Inx:=0; |
|||
repeat |
|||
begin |
|||
{Sum three factors} |
|||
Sum:=Facts[Inx]+Facts[Inx+1]+Facts[Inx+2]; |
|||
{Exit if not primve} |
|||
if not IsPrime(Sum) then exit; |
|||
{Index to next three} |
|||
Inc(Inx,3); |
|||
end |
|||
until Inx>High(Facts)-1; |
|||
Result:=True; |
|||
end; |
|||
procedure ShowCalmoNumbers(Memo: TMemo); |
|||
{Show all Calmo numbers less than 1,000} |
|||
var I,J: integer; |
|||
var S: string; |
|||
begin |
|||
for I:=1 to 1000 do |
|||
if IsCalmoNumber(I) then |
|||
begin |
|||
S:=''; |
|||
for J:=0 to High(Facts) do |
|||
S:=S+Format('%4d',[Facts[J]]); |
|||
S:=Trim(S); |
|||
Memo.Lines.Add(IntToStr(I)+' ['+S+']'); |
|||
end; |
|||
end; |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
165 [3 5 11 15 33 55] |
|||
273 [3 7 13 21 39 91] |
|||
385 [5 7 11 35 55 77] |
|||
399 [3 7 19 21 57 133] |
|||
561 [3 11 17 33 51 187] |
|||
595 [5 7 17 35 85 119] |
|||
665 [5 7 19 35 95 133] |
|||
715 [5 11 13 55 65 143] |
|||
957 [3 11 29 33 87 319] |
|||
Elapsed Time: 11.747 ms. |
|||
</pre> |
|||