Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
47
Task/Abundant-odd-numbers/Delphi/abundant-odd-numbers.delphi
Normal file
47
Task/Abundant-odd-numbers/Delphi/abundant-odd-numbers.delphi
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
program AbundantOddNumbers;
|
||||
|
||||
{$APPTYPE CONSOLE}
|
||||
|
||||
uses
|
||||
SysUtils;
|
||||
|
||||
function SumProperDivisors(const N: Cardinal): Cardinal;
|
||||
var
|
||||
I, J: Cardinal;
|
||||
begin
|
||||
Result := 1;
|
||||
I := 3;
|
||||
while I < Sqrt(N)+1 do begin
|
||||
if N mod I = 0 then begin
|
||||
J := N div I;
|
||||
Inc(Result, I);
|
||||
if I <> J then Inc(Result, J);
|
||||
end;
|
||||
Inc(I, 2);
|
||||
end;
|
||||
end;
|
||||
|
||||
var
|
||||
C, N: Cardinal;
|
||||
begin
|
||||
N := 1;
|
||||
C := 0;
|
||||
while C < 25 do begin
|
||||
Inc(N, 2);
|
||||
if N < SumProperDivisors(N) then begin
|
||||
Inc(C);
|
||||
WriteLn(Format('%u: %u', [C, N]));
|
||||
end;
|
||||
end;
|
||||
|
||||
while C < 1000 do begin
|
||||
Inc(N, 2);
|
||||
if N < SumProperDivisors(N) then Inc(C);
|
||||
end;
|
||||
WriteLn(Format('The one thousandth abundant odd number is: %u', [N]));
|
||||
|
||||
N := 1000000001;
|
||||
while N >= SumProperDivisors(N) do Inc(N, 2);
|
||||
WriteLn(Format('The first abundant odd number above one billion is: %u', [N]));
|
||||
|
||||
end.
|
||||
Loading…
Add table
Add a link
Reference in a new issue