在Ruby内建的mathn库中有方法可以直接判断整数是否为素数 require 'mathn' puts 23849382941.prime? #=>true 转载于:https://blog.51cto.com/lockrock/903244