Re: The prime factors of n.
- To: mathgroup at smc.vnet.net
- Subject: [mg32707] Re: [mg32673] The prime factors of n.
- From: BobHanlon at aol.com
- Date: Thu, 7 Feb 2002 05:09:34 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
In a message dated 2/6/02 5:44:26 AM, rgwv at kspaint.com writes:
>I wish to receive a list of prime factors of n not in the form
>returned by FactorInteger. Instead I want only the primes the number of
>times they appear. As an example I will use 72. FactorInteger[72] gives
>{ {2,3}, {3,2} }. I wish the list would read { 2, 2, 2, 3, 3 }. Is the
>following the best that I can do? f[n_Integer] := Module[{a =
>FactorInteger[n], b = {}}, While[Length[a] > 0, Do[b = Append[b, a[[1,
>1]]], {a[[1, 2]]}]; a = Drop[a, 1]]; b] .
>
f[n_Integer] := Flatten[
Table[#[[1]],{#[[2]]}]&/@FactorInteger[n]];
f[72]
{2, 2, 2, 3, 3}
Bob Hanlon
Chantilly, VA USA