project euler 16
来源:互联网 发布:sql 注入漏洞 关键字 编辑:程序博客网 时间:2024/06/08 13:39
Problem 16
Power digit sum
215 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.
What is the sum of the digits of the number 21000?
幂的数字和
215 = 32768,而32768的各位数字之和是 3 + 2 + 7 + 6 + 8 = 26。
21000的各位数字之和是多少?
package projecteuler;import org.junit.Test;public class Prj16 {/** * 2^15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26. * * What is the sum of the digits of the number 2^1000? */@Testpublic void test() {System.out.println(getSum(1000));}public int getSum(int bit) {int[] buf = new int[bit];buf[bit - 1] = 2;// 1000 - 1;for (int i = 0; i < bit - 1; i++) {for (int iter = 0; iter < bit; iter++) {buf[iter] *= 2;}for( int j = bit - 1; j > 0 ; j --){int remain = buf[j] % 10;buf[j - 1] += buf[j] / 10;buf[j] = remain;}}int sum = 0;for (int i = 0; i < bit; i++) {sum += buf[i];}return sum;}static void print_Arr( int [] arr){for( int i = 0 ; i < arr.length; i ++){System.out.println("[" + i + "]=" + arr[i]);}}}
0 0
- Project Euler Problem 16
- Project Euler problem 16
- Project Euler 16
- Project Euler 16~20
- Project Euler Problem 16
- project euler 16
- Project Euler – Problem 16
- Project Euler 16-20题
- Project Euler
- project euler
- Project Euler
- Project Euler 16: Power digit sum.
- Project Euler 题解 #16 Power digit sum
- Project Euler:Problem 16 Power digit sum
- 16 Power digit sum - Project Euler
- Project Euler Problem 16 Power digit sum
- project euler 16 Power digit sum
- Project Euler .net
- 【以太网数据包】DNS数据包
- project euler 15
- 在Spring3+Hibernate4环境中配置Quartz定时器,注入sessionFactory
- PAT甲级-1004
- OpenJudge_P1760 菲波那契数列(2)(递推)
- project euler 16
- 矩阵的转置
- 8086汇编笔记(基础知识与寄存器)
- 追女孩的心得
- 图像细化、骨架提取
- LeetCode 之 Add Binary
- Static class 与non static class的区别
- 8086汇编笔记(源程序与loop循环)
- project euler 18