Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 試割法.定義通り
- import Math._
- def isPrime(num: Int): Boolean = {
- def func(num : Int): Boolean = num match {
- case 2 => true
- case n if n < 2 => false
- case n if n%2 == 0 => false
- case n => loop(n, 3)
- }
- def loop(m : Int, i: Int): Boolean = (m , i) match {
- case (m, i) if m%i == 0 => false
- case (m, i) if pow(i, 2) > m => true
- case (m, i) => loop(m, i + 2)
- }
- func(num)
- }
- val result = isPrime(100000000)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement