I am trying to figure out this question.
Write a procedure, primeset
, whose input is a positive integer n and whose output is the set of all primes p such that p divides n.
I have tried the following so far. This is using maple.
primeset:=proc
# Determine if n is divisble by p:
local p;
for p from 1 to n do
if isprime(p) then # check divisibility by primes
if modp(n,p) = 0 then # check if divided by prime
return false;
end if;
end if;
end do;
return true;
end proc;
# VARIABLES:
# INPUT:
# n is a (positive) integer
# LOCAL:
# p is a (positive) integer.
# OUTPUT:
# output is the set of all primes p such that p divides n.
My ouput was this:
primeset := proc (n) local p; for p to n do if isprime(p) then if modp(n, p) = 0 then return false end if end if end do; return true end proc.
I tried to run it on some numbers such 2,4,and 10, and all I got was false, false, false.
If anyone can offer some suggestions then that would be great.