Jump to content

Proper divisors: Difference between revisions

Line 1,034:
<lang PowerShell>
function proper-divisor ($n) {
if($n -gegt 2) {
$lim = [Math]::Floor($n/2)+1
$proper = @(1)
Line 1,051:
</lang>
===version 2===
<lang PowerShell>
function proper-divisor ($n) {
if($n -ge 2) {
$lim = [Math]::Floor([Math]::Sqrt($n))+1
$proper = @(1)
for($i = 2; $i -lt $lim; $i++){
if($n%$i -eq 0) {
$proper += @($i)
if($i -ne ($lim-1)) {
$proper += @($n/$i)
}
}
}
$proper | sort
} else {@()}
 
}
"$(proper-divisor 100)"
"$(proper-divisor 496)"
"$(proper-divisor 2048)"
</lang>
===version 3===
<lang PowerShell>
function eratosthenes ($n) {
Line 1,082 ⟶ 1,104:
}
function proper-divisor ($n) {
if($n -gegt 2) {
$array = prime-decomposition $n
function state($arr, $cnt, $lim){
678

edits

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