Abundant odd numbers: Difference between revisions
→{{header|REXX}}: ooRexx conformance and only one loop instead of three
Walterpachl (talk | contribs) (→{{header|REXX}}: ooRexx conformance and only one loop instead of three) |
|||
(2 intermediate revisions by 2 users not shown) | |||
Line 4,514:
{{out}}
<pre>[5,25,35,175,385,1925,5005,25025,85085,425425,1616615,8083075,37182145,56581525]</pre>
=={{header|MiniScript}}==
<syntaxhighlight lang="miniscript">
divisorSum = function(n)
ans = 0
i = 1
while i * i <= n
if n % i == 0 then
ans += i
j = floor(n / i)
if j != i then ans += j
end if
i += 1
end while
return ans
end function
cnt = 0
n = 1
while cnt < 25
sum = divisorSum(n) - n
if sum > n then
print n + ": " + sum
cnt += 1
end if
n += 2
end while
while true
sum = divisorSum(n) - n
if sum > n then
cnt += 1
if cnt == 1000 then break
end if
n += 2
end while
print "The 1000th abundant number is " + n + " with a proper divisor sum of " + sum
n = 1000000001
while true
sum = divisorSum(n) - n
if sum > n and n > 1000000000 then break
n += 2
end while
print "The first abundant number > 1b is " + n + " with a proper divisor sum of " + sum
</syntaxhighlight>
{{out}}
<pre>945: 975
1575: 1649
2205: 2241
2835: 2973
3465: 4023
4095: 4641
4725: 5195
5355: 5877
5775: 6129
5985: 6495
6435: 6669
6615: 7065
6825: 7063
7245: 7731
7425: 7455
7875: 8349
8085: 8331
8415: 8433
8505: 8967
8925: 8931
9135: 9585
9555: 9597
9765: 10203
10395: 12645
11025: 11946
The 1000th abundant number is 492975 with a proper divisor sum of 519361
The first abundant number > 1b is 1000000575 with a proper divisor sum of 1083561009
</pre>
=={{header|Nim}}==
Line 5,756 ⟶ 5,833:
The '''sigO''' function is a specialized version of the '''sigma''' function optimized just for ''odd'' numbers.
<syntaxhighlight lang="rexx">/*REXX pgm displays abundant odd numbers: 1st 25,
parse arg Nlow Nuno Novr . /*obtain optional arguments from the CL*/
if Nlow=='' | Nlow==
if Nuno=='' | Nuno==
if Novr=='' | Novr==
numeric digits max(9,
d=sigO(j)
if d>j then Do
n= n
say rt(th(n)) a 'is:'rt(commas(j),8) rt('sigma=') rt(commas(d),9)
End
end /*j*/
say
d= sigO(j)
if d>j
n= n
if n>=Nuno then do /*Odd abundantn count<Nuno? Then skip.*/
say rt(th(n)) a 'is:'rt(commas(j),8) rt('sigma=') rt(commas(d),9)
leave /*we're finished displaying NUNOth num.*/
End
end /*j*/
say
d= sigO(j)
if d>j
say rt(th(1)) a 'over' commas(Novr) 'is: ' commas(j) rt('sigma=') commas(d)
Leave /*we're finished displaying NOVRth num.*/
End
end /*j*/
exit
/*--------------------------------------------------------------------------------------*/
commas:parse arg _; do c_=length(_)-3 to 1 by -3; _=insert(',',_,c_); end; return _
rt: procedure; parse arg n,len; if len=='' then len=20; return right(n,len)
th: parse arg th; return th||word('th st nd rd',1+(th//10)*(th//100%10\==1)*(th//10<4))
/*--------------------------------------------------------------------------------------*/
sigO: parse arg x;
s=1
do k=3 by 2
if x//k==0 then
s= s + k + x%k /*add the two divisors to (sigma) sum. */
end /*k*/ /* ___*/
if k*k==x then
return s + k /*Was X a square? If so,add v x */
return s /*return (sigma) sum of the divisors. */
</syntaxhighlight>
{{out|output|text= when using the default input:}}
<pre>
Line 6,691 ⟶ 6,780:
{{libheader|Wren-fmt}}
{{libheader|Wren-math}}
<syntaxhighlight lang="
import "./math" for Int, Nums
var sumStr = Fn.new { |divs| divs.reduce("") { |acc, div| acc + "%(div) + " }[0...-3] }
Line 6,707 ⟶ 6,796:
var s = sumStr.call(divs)
if (!printOne) {
} else {
}
}
|