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

前端 未结 10 1898
别跟我提以往
别跟我提以往 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:47

    For calculating the values of such big numbers you not only need to be a good programmer but also a good mathematician. Here is a hint for you, there's familiar formula ax = ex ln a , or if you prefer, ax = 10x log a.

    More specific to your problem 21000 Find the common (base 10) log of 2, and multiply it by 1000; this is the power of 10. If you get something like 1053.142 (53.142 = log 2 value * 1000) - which you most likely will - then that is 1053 x 100.142; just evaluate 100.142 and you will get a number between 1 and 10; and multiply that by 1053, But this 1053 will not be useful as 53 zero sum will be zero only.

    For log calculation in C#

    Math.Log(num, base);
    

    For more accuracy you can use, Log and Pow function of Big Integer.

    Now rest programming help I believe you can have from your side.

提交回复
热议问题