Skip to content

Commit

Permalink
Optimize PrimeFactors
Browse files Browse the repository at this point in the history
  • Loading branch information
fatosmorina committed Apr 12, 2017
1 parent da10d96 commit 8bcde5e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions UVa/PrimeFactors.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,20 @@ public class PrimeFactors {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int number = input.nextInt();
boolean[] isPrime = generatePrimeNumbers();
while (number != 0) {
boolean isNegative = false;
if (number < 0) {
isNegative = true;
number = Math.abs(number);
}
int originalNumber = number;
formatOutput(originalNumber, sieveOfEratosthenes(originalNumber), isNegative);
formatOutput(originalNumber, sieveOfEratosthenes(isPrime, originalNumber), isNegative);
number = input.nextInt();
}
}

public static List<Integer> sieveOfEratosthenes(int number) {
boolean[] isPrime = generatePrimeNumbers();
public static List<Integer> sieveOfEratosthenes(boolean[] isPrime, int number) {
List<Integer> primeFactors = new ArrayList<Integer>();
int squareRootOfOriginalNumber = (int) Math.sqrt(number);
for (int i = 2; i <= squareRootOfOriginalNumber; i++) {
Expand Down

0 comments on commit 8bcde5e

Please sign in to comment.