Factors of an integer: Difference between revisions

→‎{{header|J}}: Rm extra whitespace
(→‎{{header|J}}: Rm extra whitespace)
Line 42:
J has a primitive, q: which returns its prime factors.
 
<lang J>q: 40
2 2 2 5</lang>
 
Alternatively, q: can produce provide a table of the exponents of the unique relevant prime factors
 
<lang J>__ q: 40
2 5
3 1</lang>
Line 53:
With this, we can form lists of each of the potential relevant powers of each of these prime factors
 
<lang J>((^ i.@>:)&.>/) __ q: 40</lang>
┌───────┬───┐
│1 2 4 8│1 5│
Line 60:
From here, it's a simple matter to compute all possible factors of the original number
 
<lang J>factors=: */&>@{@((^ i.@>:)&.>/)@q:~&__</lang>
 
<lang J>factors 40
1 5
2 10
Anonymous user