project euler 30
来源:互联网 发布:mac如何打开msg文件 编辑:程序博客网 时间:2024/05/21 11:29
Problem 30
Digit fifth powers
Surprisingly there are only three numbers that can be written as the sum of fourth powers of their digits:
1634 = 14 + 64 + 34 + 44
8208 = 84 + 24 + 04 + 84
9474 = 94 + 44 + 74 + 44
As 1 = 14 is not a sum it is not included.
The sum of these numbers is 1634 + 8208 + 9474 = 19316.
Find the sum of all the numbers that can be written as the sum of fifth powers of their digits.
各位数字的五次幂
令人惊讶的是,只有三个数可以写成它们各位数字的四次幂之和:
1634 = 14 + 64 + 34 + 44
8208 = 84 + 24 + 04 + 84
9474 = 94 + 44 + 74 + 44
由于1 = 14不是一个和,所以这里并没有把它包括进去。
这些数的和是1634 + 8208 + 9474 = 19316。
找出所有可以写成它们各位数字的五次幂之和的数,并求这些数的和。
package projecteuler;import java.util.ArrayList;import java.util.List;import org.junit.Test;public class Prj30 {/** * Surprisingly there are only three numbers that can be written as the sum * of fourth powers of their digits: * * 1634 = 14 + 64 + 34 + 44 8208 = 84 + 24 + 04 + 84 9474 = 94 + 44 + 74 + * 44 As 1 = 14 is not a sum it is not included. * * The sum of these numbers is 1634 + 8208 + 9474 = 19316. * * Find the sum of all the numbers that can be written as the sum of fifth * powers of their digits. */@Testpublic void test() {int sum = 0;for (int i = 10; i < Math.pow(10, 6); i++) {if (checkCondition(i)) {System.out.println(i);sum += i;}}System.out.println("sum=" + sum);}private boolean checkCondition(int val) {List<Integer> data = new ArrayList<Integer>();int num = val;while( num >= 10){data.add(num % 10);num /= 10;}data.add(num);int sum = 0;for( int i = 0 ; i < data.size(); i ++){sum += Math.pow(data.get(i), 5);}return sum == val;}public static class CalculateParams{/** * 横向网格点数 */public int m;/** * 纵向网格个数 */public int n;/** * 网格间距 */public int netSize;/** * 网格点数值 */public double[] val;/** * 等直面数值数组 */public double[] contourVal;/** * 等直面个数 */public int coutourNum;}}
0 0
- Project Euler Problem 30
- Project Euler - Problem 30
- Project Euler problem 30
- Project Euler 30
- project euler problem 30
- Python-Project Euler 30
- Project Euler 26~30
- Project Euler Problem 30
- project euler 30
- Project euler problem 21 - 30
- Project Euler 26-30题
- Project Euler
- project euler
- Project Euler
- Project Euler 题解 #30 Digit fifth powers
- Project Euler:Problem 30 Digit fifth powers
- Project Euler .net
- Project Euler 0
- 04 BloomFilter
- c++单独编译
- Windows程序设计(Hello,word!)
- project euler 29
- 印度足球之最
- project euler 30
- 使用Gson解析json格式的字符串的正确方式
- struts2必备包
- Android自定义组件之圆形图片
- 过滤器及监听器
- 38.XML数据解析的SAX解析
- Windows程序设计(与窗口的第一次)
- char *s 与 char s[]的区别
- LightOJ 1140How Many Zeroes?