19 October, 2008

[Project Euler] Problem 16

Problem 16

java.math.BigIntegerを使うだけ。

object P016 {
def main(args:Array[String]) {
val v2 = new BigInt(java.math.BigInteger.valueOf(2L))
val r = v2.pow(1000).toString.toCharArray.map{c => c-'0'}.foldLeft(0)(_+_)
println(r)
}
}

No comments: