Proper divisors: Difference between revisions

Content added Content deleted
(add fermat)
(Added Forth)
Line 2,311: Line 2,311:
10 1, 2, 5
10 1, 2, 5
The number up to 20,000 with the most divisors was 15120 with 79 divisors.</pre>
The number up to 20,000 with the most divisors was 15120 with 79 divisors.</pre>


=={{header|Forth}}==

{{works with|gforth|0.7.3}}

<lang forth>: .proper-divisors
dup 1 ?do
dup i mod 0= if i . then
loop cr drop
;

: proper-divisors-count
0 swap
dup 1 ?do
dup i mod 0= if swap 1 + swap then
loop drop
;

: rosetta-proper-divisors
cr
11 1 do
i . ." : " i .proper-divisors
loop

1 0
20000 2 do
i proper-divisors-count
2dup < if nip nip i swap else drop then
loop
swap cr . ." has " . ." divisors" cr
;

rosetta-proper-divisors</lang>

{{out}}
<pre>1 :
2 : 1
3 : 1
4 : 1 2
5 : 1
6 : 1 2 3
7 : 1
8 : 1 2 4
9 : 1 3
10 : 1 2 5

15120 has 79 divisors
ok</pre>



=={{header|Fortran}}==
=={{header|Fortran}}==