Package net.n1da.dev.euler
Class PE0021
- java.lang.Object
-
- net.n1da.dev.euler.core.Problem
-
- net.n1da.dev.euler.PE0021
-
- All Implemented Interfaces:
Solvable
public class PE0021 extends Problem
Solution for problem 21 "Amicable numbers" completed on Sun, 24 May 2015, 06:32.- Since:
- 24.05.2015 06:09:13
- Author:
- Nico Danneberg
- See Also:
- Problem @ Project Euler, Solution @ Ni-Da-Net
-
-
Method Summary
Modifier and Type Method Description private boolean
isAmicable(long num)
Checks the given number to be a amicable number.void
prepare()
Just initializes thecache
as empty memory.java.lang.String
solve()
Runs a loop to 10000 and checks if the current number is amicable.-
Methods inherited from class net.n1da.dev.euler.core.Problem
finish, getResult, getRuntime, toString
-
-
-
-
Method Detail
-
prepare
public void prepare()
Just initializes thecache
as empty memory.
-
solve
public java.lang.String solve()
Runs a loop to 10000 and checks if the current number is amicable. A found amicable number is added to final sum.- Returns:
- the sum of all found amicable numbers
- See Also:
isAmicable(long)
-
isAmicable
private boolean isAmicable(long num)
Checks the given number to be a amicable number. Therefore first thecache
is asked. If the number could not be found incache
thesum of divisors
is calculated.- Parameters:
num
- the number to be checked- Returns:
- true if the number is amicable
- See Also:
Mathe.getSumOfDivisors(long)
-
-