Skip to content

Instantly share code, notes, and snippets.

@rirakkumya
Created February 1, 2012 01:12
Show Gist options
  • Save rirakkumya/1714335 to your computer and use it in GitHub Desktop.
Save rirakkumya/1714335 to your computer and use it in GitHub Desktop.
素数判定
def prime(n:Int) = !(2 to scala.math.sqrt(n).toInt exists(n % _ == 0))
assert(List(2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97).filter(prime(_) == false).size == 0)
assert(List(4,6,8,9,10).filter(prime(_) == true).size == 0)
//2~nまでの素数リスト
def plist(n:Int) = 2 to n filter(prime(_) == true)
def plist(n:Int) = 2 to n filter(BigInt(_).isProbablePrime(64) == true)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment