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 {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuffer sb = new StringBuffer();
String m="";
int[][]arr=new int[101][100];
for(int i=2;i<arr.length;i++){
System.arraycopy(arr[i-1], 2, arr[i], 2, 100 - 2);
LinkedList<Integer> list=primeFactors(i);
while(!list.isEmpty()){
int temp=list.remove();
arr[i][temp]++;
}
}
while(true){
int x=Integer.parseInt(br.readLine());
if(x==0){
break;
}
String str=String.format("%3d! =", x);
sb.append(str);
int counter=0;
boolean flag=false;
for(int i=2;i<100;i++){
if(arr[x][i]>0){
if(flag){
sb.append(" ");
flag=false;
}
str=String.format("%3d", arr[x][i]);
sb.append(str);
counter++;
if(counter%15==0){
sb.append("\n");
flag=true;
}
}
}
if(!flag){
sb.append("\n");
}
}
System.out.print(sb);
}
static LinkedList<Integer> 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);
}
return list;
}
}
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedList;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuffer sb = new StringBuffer();
String m="";
int[][]arr=new int[101][100];
for(int i=2;i<arr.length;i++){
System.arraycopy(arr[i-1], 2, arr[i], 2, 100 - 2);
LinkedList<Integer> list=primeFactors(i);
while(!list.isEmpty()){
int temp=list.remove();
arr[i][temp]++;
}
}
while(true){
int x=Integer.parseInt(br.readLine());
if(x==0){
break;
}
String str=String.format("%3d! =", x);
sb.append(str);
int counter=0;
boolean flag=false;
for(int i=2;i<100;i++){
if(arr[x][i]>0){
if(flag){
sb.append(" ");
flag=false;
}
str=String.format("%3d", arr[x][i]);
sb.append(str);
counter++;
if(counter%15==0){
sb.append("\n");
flag=true;
}
}
}
if(!flag){
sb.append("\n");
}
}
System.out.print(sb);
}
static LinkedList<Integer> 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);
}
return list;
}
}
No comments:
Post a Comment