Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fromLeonard;
- import java.util.ArrayList;
- /**
- * A utility class to find the prime factorilization of positive integers.
- *
- * @author Pi-Nerd Fisher
- * @version 1.0
- */
- public class PrimeFactorilization {
- /**
- * Finds the prime factors of any positive integer.
- *
- * @param i
- * the number to find the prime factors of
- * @return an ArrayList with the factors, ordered from least to greatest
- */
- public static ArrayList<Integer> primeFactors(int i) {
- Primes foo = new Primes(i);
- ArrayList<Integer> primes = foo.getList();
- ArrayList<Integer> factors = new ArrayList<Integer>();
- int k = 0;
- while (k < primes.size()) {
- if (i % primes.get(k) == 0) {
- factors.add(primes.get(k));
- i/=primes.get(k);
- } else {
- k++;
- }
- }
- return factors;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement