我试图使用尾递归函数来检查这个值是否是素数,所以请有人帮我做这个。
`
declare
fun {PrimeR X D}
if X==2 orelse X==3 then 1
elseif X<2 andthen ((X mod D)==0) andthen D =< X then 0
elseif ((X mod D)\=0) then 1
else {PrimeR X D+1}
end
end
{Browse {PrimeR 6 1}}`
发布于 2022-11-06 21:51:23
如果你想使用迭代函数的话
declare
fun {IsPrime X}
fun {PrimeItter X N}
case (X mod N) of 0 then X==N
else {PrimeItter X N+1} end
end
in
{PrimeItter X 2}
end
{Browse {IsPrime 31}}https://stackoverflow.com/questions/74338425
复制相似问题