mirror of
https://bitbucket.org/Mattrixwv/javaclasses.git
synced 2025-12-06 15:03:58 -05:00
Updated algorithm to get factors of number
This commit is contained in:
@@ -238,7 +238,7 @@ public class NumberAlgorithms{
|
||||
}
|
||||
public static List<Long> getFactors(long goalNumber) throws InvalidResult{
|
||||
//You need to get all the primes that could be factors of this number so you can test them
|
||||
Double topPossiblePrime = Math.ceil(Math.sqrt(goalNumber));
|
||||
Double topPossiblePrime = Math.ceil(goalNumber / 2.0);
|
||||
List<Long> primes = getPrimes(topPossiblePrime.longValue());
|
||||
ArrayList<Long> factors = new ArrayList<>();
|
||||
|
||||
@@ -272,7 +272,7 @@ public class NumberAlgorithms{
|
||||
}
|
||||
public static List<BigInteger> getFactors(BigInteger goalNumber) throws InvalidResult{
|
||||
//You need to get all the primes that could be factors of this number so you can test them
|
||||
BigInteger topPossiblePrime = goalNumber.sqrt();
|
||||
BigInteger topPossiblePrime = goalNumber.divide(BigInteger.TWO);
|
||||
List<BigInteger> primes = getPrimes(topPossiblePrime);
|
||||
ArrayList<BigInteger> factors = new ArrayList<>();
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
package com.mattrixwv.exceptions;
|
||||
|
||||
|
||||
public class InvalidResult extends Exception{
|
||||
public class InvalidResult extends RuntimeException{
|
||||
private static final long serialVersionUID = 1L;
|
||||
public InvalidResult(){
|
||||
super();
|
||||
|
||||
Reference in New Issue
Block a user