程式碼如下:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
class a010 {
/* 0.1s, 468KB */
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
System.out.print(prime(n) + "\n");
}
static String prime(int n) {
String res = "";
for (int i = 2; i <= n; i++) {
int pow = 0;
while (n % i == 0) {
n /= i;
pow++;
}
if (pow > 1) {
res += i + "^" + pow;
if (n > 1)
res += " * ";
} else if (pow == 1) {
res += i;
if (n > 1)
res += " * ";
}
}
return res;
}
}