Created
December 28, 2012 12:49
-
-
Save kazua/4397457 to your computer and use it in GitHub Desktop.
Project Euler Problem 47
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //http://odz.sakura.ne.jp/projecteuler/index.php?cmd=read&page=Problem%2047 | |
| //K.A | |
| import scala.math._ | |
| object problem47 { | |
| def getConPfnFst(cnt : Int) : Int = { | |
| lazy val pr : Stream[Int] = 2 #:: Stream.from(3).filter(i=> pr.takeWhile(j=> BigInt(j).pow(2) <= i).forall(i % _ > 0)) | |
| Stream.from(2).dropWhile(i=> (0 until cnt).map(j => pr.take(ceil(sqrt(i+j)).toInt).filter((i+j) % _ == 0).size).forall(_ == cnt)==false).take(1).min | |
| } | |
| def main(args : Array[String]) { | |
| val cnt = 4 | |
| println(getConPfnFst(cnt)) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment