小米儿1234
幼苗
共回答了13个问题采纳率:100% 举报
求素数,没有公式,只能自己编写过程.例:判断x是不是素数.for i=2 to x
if x%i=0 then
break
end if
next
if x=i then
printf x "not 素数"
else
print x "is 素数"
end if
1年前
追问
3
心惊胆战的小可怜
举报
谢谢啊 如果公式改成 if x mod 2 and x mod 3 then x 不是素数 else x 是素数 end if 这样可以吗? 明天考试我想弄明白点
举报
小米儿1234
不好意思,刚才打错一个符号,应该是x mod i,你写的只能判断2,3二个因子。所以,不行。