Abundant odd numbers: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (Automated syntax highlighting fixup (second round - minor fixes)) |
|||
Line 3,035: | Line 3,035: | ||
=={{header|FutureBasic}}== |
=={{header|FutureBasic}}== |
||
{{trans|C}} |
{{trans|C}} |
||
FB's 'cln' keyword is used to enter a line of C or Objective-C code. |
|||
<syntaxhighlight lang="futurebasic"> |
<syntaxhighlight lang="futurebasic"> |
||
include "NSLog.incl" |
include "NSLog.incl" |
||
Line 3,055: | Line 3,057: | ||
HandleEvents |
HandleEvents |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
The following is pure FB code. |
|||
<syntaxhighlight lang="futurebasic"> |
|||
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 |
|||
</syntaxhighlight> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |