Proper divisors: Difference between revisions

no edit summary
No edit summary
Line 1,486:
Tuple!(uint, int)(79, 18480)</pre>
The Run-time is about 0.67 seconds with the ldc2 compiler.
 
=={{header|Delphi}}==
{{trans|C#}}
<lang Delphi>
program ProperDivisors;
 
{$APPTYPE CONSOLE}
 
{$R *.res}
 
uses
System.SysUtils,
System.Generics.Collections;
 
type
TProperDivisors = TArray<Integer>;
 
function GetProperDivisors(const value: Integer): TProperDivisors;
var
i, count: Integer;
begin
count := 0;
 
for i := 1 to value div 2 do
begin
if value mod i = 0 then
begin
inc(count);
SetLength(result, count);
Result[count - 1] := i;
end;
end;
end;
 
procedure Println(values: TProperDivisors);
var
i: Integer;
begin
Write('[');
if Length(values) > 0 then
for i := 0 to High(values) do
Write(Format('%2d', [values[i]]));
Writeln(']');
end;
 
var
number, max_count, count, max_number: Integer;
 
begin
for number := 1 to 10 do
begin
write(number, ': ');
Println(GetProperDivisors(number));
end;
 
max_count := 0;
for number := 1 to 20000 do
begin
count := length(GetProperDivisors(number));
if count > max_count then
begin
max_count := count;
max_number := number;
end;
end;
 
Write(max_number, ': ', max_count);
 
readln;
end.
</lang>
{{out}}
<pre>
1: []
2: [ 1]
3: [ 1]
4: [ 1 2]
5: [ 1]
6: [ 1 2 3]
7: [ 1]
8: [ 1 2 4]
9: [ 1 3]
10: [ 1 2 5]
15120: 79
</pre>
 
=={{header|Dyalect}}==
478

edits