Jump to content

Abundant odd numbers: Difference between revisions

Add CLU
(Added XPL0 example.)
(Add CLU)
Line 2,280:
The first abundant odd number above one billion is:
1000000575 < 1 + 3 + 5 + 7 + 9 + 15 + 21 + 25 + 35 + 45 + 49 + 63 + 75 + 105 + 147 + 175 + 225 + 245 + 315 + 441 + 525 + 735 + 1225 + 1575 + 2205 + 3675 + 11025 + 90703 + 272109 + 453515 + 634921 + 816327 + 1360545 + 1904763 + 2267575 + 3174605 + 4081635 + 4444447 + 5714289 + 6802725 + 9523815 + 13333341 + 15873025 + 20408175 + 22222235 + 28571445 + 40000023 + 47619075 + 66666705 + 111111175 + 142857225 + 200000115 + 333333525 = 1083561009</pre>
 
=={{header|CLU}}==
<lang clu>% Integer square root
isqrt = proc (s: int) returns (int)
x0: int := s / 2
if x0 = 0 then
return(s)
else
x1: int := (x0 + s/x0) / 2
while x1 < x0 do
x0 := x1
x1 := (x0 + s/x0) / 2
end
return(x0)
end
end isqrt
 
% Calculate aliquot sum (for odd numbers only)
aliquot = proc (n: int) returns (int)
sum: int := 1
for i: int in int$from_to_by(3, isqrt(n)+1, 2) do
if n//i = 0 then
j: int := n / i
sum := sum + i
if i ~= j then
sum := sum + j
end
end
end
return(sum)
end aliquot
 
% Generate abundant odd numbers
abundant_odd = iter (n: int) yields (int)
while true do
if n < aliquot(n) then yield(n) end
n := n + 2
end
end abundant_odd
 
start_up = proc ()
po: stream := stream$primary_output()
count: int := 0
for n: int in abundant_odd(1) do
count := count + 1
if count <= 25 cor count = 1000 then
stream$putl(po, int$unparse(count)
|| ":\t"
|| int$unparse(n)
|| "\taliquot: "
|| int$unparse(aliquot(n)))
if count = 1000 then break end
end
end
for n: int in abundant_odd(1000000001) do
stream$putl(po, "First above 1 billion: "
|| int$unparse(n)
|| " aliquot: "
|| int$unparse(aliquot(n)))
break
end
end start_up</lang>
{{out}}
<pre>1: 945 aliquot: 975
2: 1575 aliquot: 1649
3: 2205 aliquot: 2241
4: 2835 aliquot: 2973
5: 3465 aliquot: 4023
6: 4095 aliquot: 4641
7: 4725 aliquot: 5195
8: 5355 aliquot: 5877
9: 5775 aliquot: 6129
10: 5985 aliquot: 6495
11: 6435 aliquot: 6669
12: 6615 aliquot: 7065
13: 6825 aliquot: 7063
14: 7245 aliquot: 7731
15: 7425 aliquot: 7455
16: 7875 aliquot: 8349
17: 8085 aliquot: 8331
18: 8415 aliquot: 8433
19: 8505 aliquot: 8967
20: 8925 aliquot: 8931
21: 9135 aliquot: 9585
22: 9555 aliquot: 9597
23: 9765 aliquot: 10203
24: 10395 aliquot: 12645
25: 11025 aliquot: 11946
1000: 492975 aliquot: 519361
First above 1 billion: 1000000575 aliquot: 1083561009</pre>
 
=={{header|Common Lisp}}==
Line 2,398 ⟶ 2,490:
54,820,848 bytes consed
</pre>
 
=={{header|D}}==
{{trans|C++}}
2,114

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.