What is the sum of the digits of the number 2^1000?

前端 未结 10 1839
别跟我提以往
别跟我提以往 2021-01-02 03:13

This is a problem from Project Euler, and this question includes some source code, so consider this your spoiler alert, in case you are interested in solving it yourself. It

10条回答
  •  孤城傲影
    2021-01-02 03:37

    This is not a serious answer—just an observation.

    Although it is a good challenge to try to beat Project Euler using only one programming language, I believe the site aims to further the horizons of all programmers who attempt it. In other words, consider using a different programming language.

    A Common Lisp solution to the problem could be as simple as

    (defun sum_digits (x)
        (if (= x 0)
            0
            (+ (mod x 10) (sum_digits (truncate (/ x 10))))))
    
    (print (sum_digits (expt 2 1000)))
    

提交回复
热议问题