Factors of an integer: Difference between revisions

Content added Content deleted
No edit summary
(→‎{{header|J}}: Additional technique.)
Line 100: Line 100:
4 20
4 20
8 40</lang>
8 40</lang>

A less efficient approach, in which remainders are examined up to the square root, larger factors obtained as fractions, and the combined list nubbed and sorted:

<lang J>
factors=: monad define
Y=. y"_
/:~ ~. ( , Y%]) ( #~ 0=]|Y) 1+i.>.%:y
)</lang>

<lang J>factors 40
1 2 4 5 8 10 20 40</lang>


=={{header|Java}}==
=={{header|Java}}==