16 Power digit sum - Project Euler
来源:互联网 发布:手机散热软件 编辑:程序博客网 时间:2024/06/10 03:03
package xxx.xxx.xxx;
import java.math.BigInteger;
/*
* 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 21000?
*/
public class PowerDigitSum {
public PowerDigitSum(int value, int exp){
System.out.println(this.sum(this.pow(value, exp)));
}
private BigInteger pow(int value, int exp){
BigInteger result = BigInteger.ONE;
int count = 1;
while(count<=exp){
result = result.multiply(BigInteger.valueOf(value));
count++;
}
return result;
}
private int sum(BigInteger result){
char[] strResult = result.toString().toCharArray();
int sum = 0;
for(char c: strResult){
sum+=Integer.parseInt(String.valueOf(c));
}
return sum;
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
PowerDigitSum powerDigitSum = new PowerDigitSum(2,1000);
}
}
import java.math.BigInteger;
/*
* 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 21000?
*/
public class PowerDigitSum {
public PowerDigitSum(int value, int exp){
System.out.println(this.sum(this.pow(value, exp)));
}
private BigInteger pow(int value, int exp){
BigInteger result = BigInteger.ONE;
int count = 1;
while(count<=exp){
result = result.multiply(BigInteger.valueOf(value));
count++;
}
return result;
}
private int sum(BigInteger result){
char[] strResult = result.toString().toCharArray();
int sum = 0;
for(char c: strResult){
sum+=Integer.parseInt(String.valueOf(c));
}
return sum;
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
PowerDigitSum powerDigitSum = new PowerDigitSum(2,1000);
}
}
0 0
- 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 题解 #20 Factorial digit sum
- Project Euler:Problem 20 Factorial digit sum
- Project Euler:Problem 56 Powerful digit sum
- 20 Factorial digit sum - Project Euler
- Project Euler Problem 20 Factorial digit sum
- project euler 20 Factorial digit sum
- Problem 16:Power digit sum
- Problem 16:Power digit sum
- PE 16 Power digit sum
- Problem 16 Power digit sum
- Project Euler 20 Factorial digit sum(大数乘法)
- Matlab 编程 Project Euler Problem 20 Factorial digit sum
- Appium总结(三):Rspec使用初步用法
- Codeforces Round #312 (Div. 2) C. Amr and Chemistry(数论)
- POJ 1027:The Same Game 较(chao)为(ji)复(ma)杂(fan)的模拟
- GCD之线程组
- idea 显示行号
- 16 Power digit sum - Project Euler
- Android:View绘制流程
- boost asio client
- 分享几个程序员应该知道的网站和技术博客
- javascript基本语法 5 引用类型-----去掉数组中的重复项
- 关于UIScreen的applicationFrame和bounds方法区别
- lightoj 1258 - Making Huge Palindromes 【Manacher】
- 在grub中添加win7(以及从win7来的win10)的启动项
- 如何清除windows入侵的记录