On Mon, Jun 8, 2009 at 2:40 AM, <[email protected]> wrote:
> A positive integer n is said to be a perfect power
> if there exist two positive integers a and
> b &#8805; 2 such that n = ab .
...
> I did a search at jsoftware.com on "perfect power" and did
> not find anything.
>
> any suggestions would be appreciated.

I could not understand your post, so I used the definition at
http://mathworld.wolfram.com/PerfectPower.html

Here's an implementation:

   pp=: *./@(=/@#...@~.@#, 2&<:, 0&<@#)@(#/....@q: ::0:"0)
   (#~ pp) i. 100
4 8 9 16 25 27 32 36 49 64 72 81

Breaking it down...

Fundamentally, perfect power is a set of constraints on the
number of factors which a number has.  #/....@q: will give us
the number of each of the prime factors which a number has.

However, some numbers can not be factored, because they are out
of the domain of q:, thus the ::0:"0  (I need an explicit rank zero
because the rank of verbs formed with :: is not zero).  If you
limit your use of pp to positive integers (for example, if you
never try numbers like 0), you can eliminate ::0:"0 from the
definition of pp.

Once you have the count of prime factors for a number, the
wolfram page specifies three constraints.

First, n is of the form m^k, m > 1 and k >: 2

These test correspond roughly to the comma separated tests
in PP (except I have expressed my tests in terms of the number
of prime factors the number has).  If all three tests are true (*./)
then the number is a prime power.

Does this help?

-- 
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to