import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedList;
public class Main {
public static void main(String[] args) throws IOException {
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
StringBuffer sb = new StringBuffer("");
String m = "";
while(true) {
int x=Integer.parseInt(br.readLine());
if(x==0)
break;
int[] arr=primeFactors(x);
sb.append(x).append(" =");
for(int i=0;i<arr.length;i++){
if(i>0)
sb.append(" x");
sb.append(" ").append(arr[i]);
}
sb.append("\n");
}
System.out.print(sb);
}
static int[] primeFactors(int x){
LinkedList<Integer> list=new LinkedList<Integer>();
if(x<0){
list.add(-1);
}
int temp=Math.abs(x);
boolean notprime=false,entered=false;
while(temp>1 &&!notprime){
entered=false;
for(int i=2;i<Math.sqrt(temp)+1;i++){
if(temp%i==0){
list.add(i);
temp/=i;
notprime=false;
entered=true;
break;
}
}
if(!entered)
notprime=true;
}
if(notprime){
list.add(temp);
}
int[] arr=new int[list.size()];
for(int i=0;i<arr.length;i++){
arr[i]=list.get(i);
}
return arr;
}
}
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedList;
public class Main {
public static void main(String[] args) throws IOException {
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
StringBuffer sb = new StringBuffer("");
String m = "";
while(true) {
int x=Integer.parseInt(br.readLine());
if(x==0)
break;
int[] arr=primeFactors(x);
sb.append(x).append(" =");
for(int i=0;i<arr.length;i++){
if(i>0)
sb.append(" x");
sb.append(" ").append(arr[i]);
}
sb.append("\n");
}
System.out.print(sb);
}
static int[] primeFactors(int x){
LinkedList<Integer> list=new LinkedList<Integer>();
if(x<0){
list.add(-1);
}
int temp=Math.abs(x);
boolean notprime=false,entered=false;
while(temp>1 &&!notprime){
entered=false;
for(int i=2;i<Math.sqrt(temp)+1;i++){
if(temp%i==0){
list.add(i);
temp/=i;
notprime=false;
entered=true;
break;
}
}
if(!entered)
notprime=true;
}
if(notprime){
list.add(temp);
}
int[] arr=new int[list.size()];
for(int i=0;i<arr.length;i++){
arr[i]=list.get(i);
}
return arr;
}
}
No comments:
Post a Comment