MathGroup Archive 2002

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: The prime factors of n.

  • To: mathgroup at smc.vnet.net
  • Subject: [mg32759] Re: The prime factors of n.
  • From: "Steve Durbin" <steved at vale.demon.co.uk>
  • Date: Fri, 8 Feb 2002 03:49:35 -0500 (EST)
  • References: <a3qqjj$27t$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

"Robert G. Wilson v" <rgwv at kspaint.com> wrote in message
news:a3qqjj$27t$1 at smc.vnet.net...
> Hello all,
>
>         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] .

This is probably not the best way, but it at least avoids the iterator and
list altering operations:

In[367]:=

superfactorinteger[x_Integer] := Module[{z, y},
      z = FactorInteger[x];
      q[y : {_, _}] := Table[y[[1]], {y[[2]]}];
      Flatten[Map[q, z]]];

In[368]:=
superfactorinteger[1]
superfactorinteger[72]
superfactorinteger[10101]
Out[368]=
{}
Out[369]=
{2, 2, 2, 3, 3}
Out[370]=
{3, 7, 13, 37}

Cheers,
--
Steve Durbin | Look! Minimalism comes to ASCII art!
             |                                           .





  • Prev by Date: Re: NDSolve with side conditions:
  • Next by Date: Importing & printing EPS files
  • Previous by thread: RE: The prime factors of n.
  • Next by thread: Import variable and data