__init__

http://forum.fgfugees.ca/gforum.cgi?post=4705

Mar 5th, 2015
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 1.06 KB | None | 0 0
  1. import scala.math
  2.  
  3. def isPrime(n:Int) : Boolean = {
  4.     if (n <= 1) {
  5.         return false
  6.     }
  7.  
  8.     var index : Int = 0
  9.     for (index <- 2 to math.sqrt(n).toInt) {
  10.         if (n % index == 0) {
  11.             return false
  12.         }
  13.     }
  14.  
  15.     return true
  16. }
  17.  
  18. def isMersenne(p:Int) : Boolean = {
  19.     var index : Int = 2;
  20.     for (index <- 2 until p) {
  21.         if (isPrime(index)) {
  22.             if ((math.pow(2, index)-1).toInt == p) {
  23.                 return true
  24.             }
  25.         }
  26.     }
  27.  
  28.     return false
  29. }
  30.  
  31. def main(args: Array[String]) {
  32.     var i : Int = 0
  33.     for (i <- 1 to 100) {
  34.         if (isMersenne(i) && isPrime(i)) {
  35.             println(math.pow(i, 2).toInt)
  36.         }
  37.         else if (isPrime(i)) {
  38.             println("AssFoot")
  39.         }
  40.         else if (i % 15 == 0) {
  41.             println("FootAss")
  42.         }
  43.         else if (i % 3 == 0) {
  44.             println("Foot")
  45.         }
  46.         else if (i % 5 == 0) {
  47.             println("Ass")
  48.         }
  49.         else {
  50.             println(i)
  51.         }
  52.     }
  53. }
  54.  
  55. main(null)
Add Comment
Please, Sign In to add comment