이 질문을 이해하려고합니다.출력을위한 절차, 정수 및 정수를 나누는 목록
primeset
의 입력이 양의 정수 n이고 출력이 p가 n을 나누는 모든 소수 p의 집합 인 프로 시저를 작성하십시오.
나는 지금까지 다음을 시도했다. 이것은 단풍 나무를 사용하고 있습니다.
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.
내 OUPUT이 있었다 :
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.
내가 몇 가지 숫자 2,4-, 10에서 실행하려고하고 내가 가진 모든 거짓, 거짓, 거짓이었다.
누구나 제안 할 수 있다면 좋을 것입니다.
감사합니다. 나는 그것을 시도 할 것입니다. –