How to test qualities about a number's prime factorization in maple?

84 Views Asked by At

I'm trying to write a code to test the following properties of a composite number $n$. To be more specific, for a given $n$ from (say) 200-300, I want to check if $n$ satisfies any of the following:

If $n$ has 3 or more odd prime factors

If $n=2^rp^{\alpha}$ where $r>2$

If $n=2^rp^{\alpha}q^{\beta}$ where $r>1$, or

If $n=2p^{\alpha}q^{\beta}$ where $p\equiv q\equiv 1\pmod{4}$

Where $p, q$ are odd prime numbers and $\alpha, \beta>1$.

I'm still pretty new to Maple, so any tips or pointers you can give would be much appreciated. I figure some kind of for loop would be best but I have no idea how I would do the conditional for those.

2

There are 2 best solutions below

4
On

Below is a Maple procedure for checking the second case ($n=2^rp^{\alpha}$ where $r>2$)

    IFak:=proc(n)  local S,R: R:="FALSE": S:=[op(ifactors(n)[2])]:
 if nops(S)=2 and S[1][1]=2 and S[1][2]>2  then R:="TRUE" end if:
 R
  end proc;

Now, IFak(100) gives "FALSE" and IFak(24) gives "TRUE".

You may write something like and for next cases.

0
On

The following procedure does all four of the tests you mentioned, returning a list of four booleans.

Tests:= proc(n::integer)
local F:= ifactors(n)[2];
      if n::{prime, nonpositive, identical(1)} then
           [false$4]
      else
           [nops(F) > 3 or F[1,2] > 2 and nops(F) > 2,
            nops(F)=2 and F[1,2] > 2 and F[2,2] > 1,
            nops(F)=3 and F[1,2] > 1 and F[2,2] > 1 and F[3,2] > 1,
            nops(F)=3 and F[1,2] = 1 and irem(F[2,1], 4) = 1 and F[2,2] > 1
                                     and irem(F[3,1], 4) = 1 and F[3,2] > 1
           ]
      end if
 end proc: