39 lines
728 B
Text
39 lines
728 B
Text
include "NSLog.incl"
|
|
|
|
local fn SumOfProperDivisors( n as NSUInteger ) as NSUinteger
|
|
NSUinteger i, j, sum = 1
|
|
|
|
for i = 3 to sqr(n) step 2
|
|
if ( n mod i == 0 )
|
|
sum += i
|
|
j = n/i
|
|
if ( i != j )
|
|
sum += j
|
|
end if
|
|
end if
|
|
next
|
|
end fn = sum
|
|
|
|
NSUinteger n = 1, c
|
|
|
|
while ( c < 25 )
|
|
if ( n < fn SumOfProperDivisors( n ) )
|
|
NSLog( @"%2lu: %lu", c, n )
|
|
c++
|
|
end if
|
|
n += 2
|
|
wend
|
|
|
|
while ( c < 1000 )
|
|
if ( n < fn SumOfProperDivisors( n ) ) then c++
|
|
n += 2
|
|
wend
|
|
NSLog( @"\nThe one thousandth abundant odd number is: %lu\n", n )
|
|
|
|
n = 1000000001
|
|
while ( n >= fn SumOfProperDivisors( n ) )
|
|
n += 2
|
|
wend
|
|
NSLog( @"The first abundant odd number above one billion is: %lu\n", n )
|
|
|
|
HandleEvents
|