File failed to load: https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/extensions/TeX/AmsMath.js

19 October, 2008

[Project Euler] Problem 13

Problem 13

文字列 -> BigInt の変換をして和を取るだけ。

import java.math.BigInteger

object P013 {
val input:Array[String] = Array(
"37107287533902102798797998220837590246510135740250",
...中略...
"53503534226472524250874054075591789781264330331690")
def main(args:Array[String]) {
val sum:BigInt = input.map{s => new BigInt(new BigInteger(s))}.foldLeft(new BigInt(BigInteger.ZERO))(_+_)
println(sum)
println(sum.toString.substring(0,10))
}
}

No comments: