fork download
  1. /*
  2. import Data.Char
  3.  
  4. main = do
  5. print . sum . map digitToInt . show . product $ [1..100000::Integer]
  6. print . sum . map digitToInt . show $ 2 ^ (10000::Integer)
  7.  
  8. */
  9.  
  10. import scala.math.BigInt
  11.  
  12. object Main {
  13.  
  14. def main(args: Array[String]): Unit = {
  15. println(
  16. (1 to 100000)
  17. .foldLeft(BigInt(1))(_ * BigInt(_))
  18. .toString
  19. .map( Character.digit(_, 10) )
  20. .foldLeft(0)(_ + _)
  21. )
  22.  
  23. println((BigInt(2) pow 10000)
  24. .toString
  25. .map( Character.digit(_, 10) )
  26. .foldLeft(0)(_ + _)
  27. )
  28. }
  29.  
  30. }
Time limit exceeded #stdin #stdout 15s 211648KB
stdin
Standard input is empty
stdout
Standard output is empty