Jump to content

Proper divisors: Difference between revisions

added langur language example
(Added uBasic/4tH version)
(added langur language example)
Line 3,604:
18480
</pre>
 
 
=={{header|langur}}==
{{trans|Go}}
<lang langur>val .getproper = f(.x) for[=[]] .i of .x \ 2 { if .x div .i: _for ~= [.i] }
val .cntproper = f(.x) for[=0] .i of .x \ 2 { if .x div .i: _for += 1 }
 
val .listproper = f(.x) {
if .x < 1: return null
for .i of .x {
writeln $"\.i:2; -> ", .getproper(.i)
}
writeln()
}
 
writeln "The proper divisors of the following numbers are :"
.listproper(10)
 
var .max = 0
var .most = []
for .n in 2 .. 20_000 {
val .cnt = .cntproper(.n)
if .cnt == .max {
.most = more .most, .n
} else if .cnt > .max {
.max, .most = .cnt, [.n]
}
}
 
writeln $"The following number(s) <= 20000 have the most proper divisors (\.max;)"
writeln .most</lang>
 
{{out}}
<pre>The proper divisors of the following numbers are :
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]
 
The following number(s) <= 20000 have the most proper divisors (79)
[15120, 18480]
</pre>
 
 
=={{header|Lua}}==
890

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.