Created
January 26, 2013 11:37
-
-
Save kazua/4641856 to your computer and use it in GitHub Desktop.
完全数リスト生成
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
| import scala.math._ | |
| object perfectnum { | |
| def getPfnList(mn : Int) : Seq[BigInt] = { | |
| lazy val pr : Stream[Int] = 2 #:: Stream.from(3).filter(i => pr.takeWhile(j => pow(j, 2) <= i).forall(i % _ > 0)).takeWhile(_ <= sqrt(mn * 2)) | |
| (1 to sqrt(mn * 2).toInt).map(i => (BigInt(1) << i) - 1).filter(pr.contains).map(j => j * (j + 1) / 2) | |
| } | |
| def main(args : Array[String]) { | |
| val mn = 100000000 | |
| getPfnList(mn).foreach(println) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment