算法9:What is the sum of the digits of the number 21000

Posted bors

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了算法9:What is the sum of the digits of the number 21000相关的知识,希望对你有一定的参考价值。

 

技术图片

 

 What is the sum of the digits of the number 21000

 

 

    public static int sumDigits(int n) {
        int int_retVal = 0;
        int int_pow = (int) Math.pow(2, n);

        String str_retVal = String.valueOf(int_pow);
        for (int i = 0; i < str_retVal.length(); i++) {
            int_retVal += Integer.parseInt(String.valueOf(str_retVal.charAt(i)));
        }
        System.out.println(int_pow + ",  " + int_retVal);
        return int_retVal;
    }


    public static void main(String[] args) {

        sumDigits(1000);
    }

结果

2147483647,  46

 

以上是关于算法9:What is the sum of the digits of the number 21000的主要内容,如果未能解决你的问题,请参考以下文章

「CF622F」The Sum of the k-th Powers「拉格朗日插值」

What is the bottleneck and weakness of AlphaGo?

Codeforces 622F The Sum of the k-th Powers ( 自然数幂和拉格朗日插值法 )

What is the name of the “--&gt;” operator?(Stackoverflow)

What is the maximum length of a URL in different browsers?

Codeforces 622F The Sum of the k-th Powers