Semiprime: Difference between revisions

Added Mathematica
(Added Mathematica)
Line 42:
1680 = 2 * 2 * 2 * 2 * 3 * 5 * 7,
so the result printed is actually correct.
 
=={{header|AutoHotkey}}==
{{works with|AutoHotkey_L}}
Line 235 ⟶ 236:
 
Description: factor the number and count the primes in the factorization, is it 2?
 
 
=={{header|Mathematica}}==
<lang Mathematica>semiPrimeQ[n_Integer] := Module[{factors, numfactors},
factors = FactorInteger[n] // Transpose;
numfactors = factors[[2]] // Total ;
numfactors == 2
]
</lang>
Example use: find all semiprimes less than 100:
<lang Mathematica>semiPrimeQ[#] & /@ Range[100];
Position[%, True] // Flatten</lang>
{{output}}
<pre>{4, 6, 9, 10, 14, 15, 21, 22, 25, 26, 33, 34, 35, 38, 39, 46, 49, 51,
55, 57, 58, 62, 65, 69, 74, 77, 82, 85, 86, 87, 91, 93, 94, 95}</pre>
 
 
=={{header|PARI/GP}}==
Anonymous user