public static void prime_factors(int n){
int power = 0;
for (int i = 2; i <= Math.sqrt(n); i += 2) {
if (n % i == 0) {
while (n % i == 0) {
power++;
n /= i;
}
System.out.print(i);
if (power > 1)
System.out.print("^" + power);
if (n > 1)
System.out.print(" x ");
power = 0;
}
if (i == 2) i--;
}
if (n > 1)
System.out.print(n);
}
public static void prime_factors(int n){
while (n % 2 == 0){
System.out.print(2 + " ");
n /= 2;
}
for (int i = 3; i <= Math.sqrt(n); i += 2) {
while (n % i == 0){
System.out.print(i + " ");
n /= i;
}
}
if (n > 2)
System.out.print(n);
}
public static ArrayList<Integer> prime_factors(int n){
ArrayList<Integer> result = new ArrayList<>();
while (n % 2 == 0){
result.add(2);
n /= 2;
}
for (int i = 3; i <= Math.sqrt(n); i += 2) {
while (n % i == 0){
result.add(i);
n /= i;
}
}
if (n > 2)
result.add(n);
return result;
}