Package net.n1da.dev.euler
Class PE0030
- java.lang.Object
-
- net.n1da.dev.euler.core.Problem
-
- net.n1da.dev.euler.PE0030
-
- All Implemented Interfaces:
Solvable
- Direct Known Subclasses:
PE0034
public class PE0030 extends Problem
Solution for problem 30 "Digit fifth powers" completed on Fri, 11 Dec 2015, 23:34- Since:
- 15.10.2015 19:33:27
- Author:
- Nico Danneberg
- See Also:
- Problem @ Project Euler, Solution @ Ni-Da-Net
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Hashtable<LargeNumber,LargeNumber>
cache
Stores the sums of the powered digits.
-
Constructor Summary
Constructors Modifier Constructor Description PE0030()
protected
PE0030(int num, java.lang.String tit)
A simple base constructor to set the givenProblem.number
andProblem.title
.
-
Method Summary
Modifier and Type Method Description protected LargeNumber
getDigitSum(LargeNumber num)
Calculates the sum of all digits of the given number.void
prepare()
Just thecache
is initialized.java.lang.String
solve()
Beginning with 10 all numbers to 500.000 are tested, if the sum of its powered digits are equal to the number itself.-
Methods inherited from class net.n1da.dev.euler.core.Problem
finish, getResult, getRuntime, toString
-
-
-
-
Field Detail
-
cache
protected java.util.Hashtable<LargeNumber,LargeNumber> cache
Stores the sums of the powered digits. As keys the sorted digits are used.
-
-
Constructor Detail
-
PE0030
public PE0030()
-
PE0030
protected PE0030(int num, java.lang.String tit)
A simple base constructor to set the givenProblem.number
andProblem.title
. In this special case it's needed for inheritance toPE0034
.- Parameters:
num
- - the number of this problemtit
- - the title of this problem
-
-
Method Detail
-
prepare
public void prepare()
Just thecache
is initialized.
-
solve
public java.lang.String solve()
Beginning with 10 all numbers to 500.000 are tested, if the sum of its powered digits are equal to the number itself. To speed up the search, thecache
is used to reduce the power calculations.- Returns:
- the sum of all found numbers that are equals to their powered digit sum
-
getDigitSum
protected LargeNumber getDigitSum(LargeNumber num)
Calculates the sum of all digits of the given number. Therefore every digit is powered by 5.- Parameters:
num
- aLargeNumber
to calculate the sum of its digits- Returns:
- the sum of the power 5 digits as new
LargeNumber
- See Also:
LargeNumber.sumOfDigitPowers(int)
-
-