Product of min and max prime factors: Difference between revisions
Product of min and max prime factors (view source)
Revision as of 23:29, 31 October 2022
, 1 year ago→{{header|AppleScript}}: Dedicated primeFactors handler. Multiplications moved to task code.
m (→{{header| Haskell}}: Added a draft in Haskell) |
m (→{{header|AppleScript}}: Dedicated primeFactors handler. Multiplications moved to task code.) |
||
Line 78:
end isPrime
on primeFactors(n)
if
set output to {}
if ((sqrt = sqrt div 1) and (isPrime(sqrt))) then
set end of output to sqrt div 1
set sqrt to sqrt - 1
end if
repeat with i from (sqrt div 1) to 2 by -1
if (n mod i is 0) then
if (isPrime(i)) then set
if (isPrime(n div i)) then set
end if
end repeat
return
end primeFactors
on join(lst, delim)
Line 99 ⟶ 104:
end join
on
set output to {""}
set thisLine to {" 1"}
repeat with n from
tell primeFactors(n) to set product to (its end) * (its beginning)
set
if (n mod 10 is 0) then
set
set thisLine to {}
end if
end repeat
return join(output, linefeed)
end
{{output}}
|