Proper divisors: Difference between revisions

(GP)
Line 213:
Tuple!(uint, int)(79, 18480)</pre>
The Run-time is about 0.67 seconds with the ldc2 compiler.
=={{header|Eiffel}}==
<lang Eiffel>
class
APPLICATION
 
create
make
 
feature
 
make
-- Test the feature proper_divisors.
local
list: LINKED_LIST [INTEGER]
count, number: INTEGER
do
across
1 |..| 10 as c
loop
list := proper_divisors (c.item)
io.put_string (c.item.out + ": ")
across
list as l
loop
io.put_string (l.item.out + " ")
end
io.new_line
end
across
1 |..| 20000 as c
loop
list := proper_divisors (c.item)
if list.count > count then
count := list.count
number := c.item
end
end
io.put_string (number.out + " has with " + count.out + "divisors the highest number of proper divisors.")
end
 
proper_divisors (n: INTEGER): LINKED_LIST [INTEGER]
-- Proper divisors of 'n'.
do
create Result.make
across
1 |..| (n - 1) as c
loop
if n \\ c.item = 0 then
Result.extend (c.item)
end
end
end
 
end
</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
15200 has with 75 divisors the highest number of proper divisors.
</pre>
 
=={{header|Fortran}}==
Compiled using G95 compiler, run on x86 system under Puppy Linux
Anonymous user