作者在 2015-02-17 22:16:26 发布以下内容
messagebox(iif(isPrime(2)=.t.,"质数","非质数"))
FUNCTION isPrime(n)
LOCAL i
IF n <= 3
RETURN n > 1
ENDIF
IF (n % 2 == 0) OR (n % 3 == 0)
RETURN .F.
ENDIF
i = 5
DO WHILE i * i <= n
IF (n % i == 0) OR (n % (i + 2) == 0)
RETURN .F.
ENDIF
i = i + 6
ENDDO
RETURN .T.
ENDFUNC