Amicable pairs: Difference between revisions
Content added Content deleted
(→{{header|ANSI Standard BASIC}}: Changed to {{header|ANSI BASIC}}; {{works with|Decimal BASIC}}; output.) |
(Initial FutureBasic task solution added) |
||
Line 2,695: | Line 2,695: | ||
in map (fn (np,mp) => [#1 np, #1 mp]) amicable |
in map (fn (np,mp) => [#1 np, #1 mp]) amicable |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
=={{header|FutureBasic}}== |
|||
<syntaxhighlight lang="futurebasic"> |
|||
local fn Sigma( n as long ) as long |
|||
long i, root, sum = 1 |
|||
if n == 1 then exit fn = 0 |
|||
root = sqr(n) |
|||
for i = 2 to root |
|||
if ( n mod i == 0 ) then sum += i + n/i |
|||
next |
|||
if root * root == n then sum -= root |
|||
end fn = sum |
|||
void local fn CalculateAmicablePairs( limit as long ) |
|||
long i, m |
|||
printf @"\nAmicable pairs through %ld are:\n", limit |
|||
for i = 2 to limit |
|||
m = fn Sigma(i) |
|||
if ( m > i ) |
|||
if ( fn Sigma(m) == i ) then printf @"%6ld and %ld", i, m |
|||
end if |
|||
next |
|||
end fn |
|||
CFTimeInterval t |
|||
t = fn CACurrentMediaTime |
|||
fn CalculateAmicablePairs( 20000 ) |
|||
printf @"\nCompute time: %.3f ms",(fn CACurrentMediaTime-t)*1000 |
|||
HandleEvents |
|||
</syntaxhighlight> |
|||
{{output}} |
|||
<pre> |
|||
Amicable pairs through 20000 are: |
|||
220 and 284 |
|||
1184 and 1210 |
|||
2620 and 2924 |
|||
5020 and 5564 |
|||
6232 and 6368 |
|||
10744 and 10856 |
|||
12285 and 14595 |
|||
17296 and 18416 |
|||
Compute time: 28.701 ms |
|||
</pre> |
|||
=={{header|GFA Basic}}== |
=={{header|GFA Basic}}== |