Proper divisors: Difference between revisions
→{{header|langur}}
No edit summary |
Langurmonkey (talk | contribs) |
||
(14 intermediate revisions by 8 users not shown) | |||
Line 1,342:
<pre>
Igual que la entrada de FreeBASIC o PureBasic.
</pre>
==={{header|Craft Basic}}===
<syntaxhighlight lang="basic">let m = 1
let l = 10
if l >= 1 then
for i = 1 to l
if i = 1 then
print i, " : (None)"
else
for j = 1 to int(i / 2)
if i % j = 0 then
print i, " :", j
endif
next j
endif
next i
endif
for n = 2 to 20000
let c = 0
if n >= 2 then
for i = 1 to int(n / 2)
if n % i = 0 then
let c = c + 1
endif
next i
endif
if c > x then
let x = c
let m = n
endif
wait
next n
print m, " has the most proper divisors", comma, " namely ", x</syntaxhighlight>
{{out| Output}}<pre>
1 : (None)
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 the most proper divisors, namely 79
</pre>
Line 2,168 ⟶ 2,242:
10: [1, 2, 5]
15120: 79</pre>
=={{header|EasyLang}}==
<syntaxhighlight>
proc propdivs n . divs[] .
divs[] = [ ]
if n < 2
return
.
divs[] &= 1
sqr = sqrt n
for d = 2 to sqr
if n mod d = 0
divs[] &= d
if d <> sqr
divs[] &= n / d
.
.
.
.
for i to 10
propdivs i d[]
write i & ":"
print d[]
.
for i to 20000
propdivs i d[]
if len d[] > max
max = len d[]
maxi = i
.
.
print maxi & " has " & max & " proper divisors."
</syntaxhighlight>
=={{header|EchoLisp}}==
Line 2,688 ⟶ 2,795:
</pre>
=={{header|Frink}}==
Line 3,536 ⟶ 3,568:
Use <code>factor</code> to obtain the prime factorization of the target number. I adopted the argument handling style of <code>factor</code> in my <code>properdivisors</code> function.
<syntaxhighlight lang="julia">
using Primes
function properdivisors(n::T) where {T<:Integer}
0 < n || throw(ArgumentError("number to be factored must be ≥ 0, got $n"))
1 < n || return T[]
!isprime(n) || return T[one(T)
f = factor(n)
d = T[one(T)]
Line 3,661 ⟶ 3,694:
=={{header|langur}}==
{{trans|Go}}
<syntaxhighlight lang="langur">val .getproper = fn(.x) { for[=[]] .i of .x \ 2 { if .x div .i: _for ~= [.i] } }
val .listproper =
if .x < 1: return null
for[=""] .i of .x {
}
}
writeln "The proper divisors of the following numbers are :"
writeln .listproper(10)
var .max = 0
Line 5,814 ⟶ 5,845:
9 -> 1 3
10 -> 1 2 5
</pre>
=={{header|RPL}}==
{{works with|HP|49}}
≪ DIVIS REVLIST TAIL REVLIST <span style="color:grey">@ or DIVIS 1 OVER SIZE 1 - SUB</span>
≫ '<span style="color:blue">PDIVIS</span>' STO
≪ 0 → max n
≪ 0
1 max '''FOR''' j
j <span style="color:blue">PDIVIS</span> SIZE
'''IF''' DUP2 < '''THEN''' SWAP j 'n' STO '''END'''
DROP
'''NEXT'''
DROP n DUP <span style="color:blue">PDIVIS</span> SIZE
≫ ≫ '<span style="color:blue">TASK2</span>' STO
≪ n <span style="color:blue">PDIVIS</span> ≫ 'n' 1 10 1 SEQ
20000 <span style="color:blue">TASK2</span>
{{out}}
<pre>
3: {{} {1} {1} {1 2} {1} {1 2 3} {1} {1 2 4} {1 3} {1 2 5}}
2: 15120
1: 39
</pre>
Line 6,132 ⟶ 6,187:
{{trans|Raku}}
<syntaxhighlight lang="ruby">func propdiv (n) {
n.divisors.
}
Line 6,474 ⟶ 6,529:
{{libheader|Wren-fmt}}
{{libheader|Wren-math}}
<syntaxhighlight lang="
import "./math" for Int
for (i in 1..10) System.print("%(Fmt.d(2, i)) -> %(Int.properDivisors(i))")
|