//输入一个整数n
//若n<2,输出0
//若n是质数,输出n的值
//若n不是质数,输出n的质因子分解式。6=2*3 8=2*2*2
//小于n的质数都存储到链表中(正序头插法 或者 逆序尾插法
#include<stdio.h>
#include<stdlib.h>
typedef struct Node {
int data;
struct Node *next;
} Node;
int main() {
int n,i,count;
Node *head,*p;
scanf("%d",&n);
head=(Node*)malloc(sizeof(Node));
head->next=NULL;
if(n<2) {
printf("0");
return 0;
} else {
for(i=2; i<n; i++) {
if(n%i==0) { //非素数
break;
}
}
if(i==n) { //素数
printf("%d",n);
return 0;
}
}
for(i=n-1; i>1; i--) { //把小于n的质数都存储到链表中,逆序头插
if(n%i==0) {
p=(Node*)malloc(sizeof(Node));
p->data=i;
p->next=head->next;
head->next=p;
}
}
p=head->next;
count=0;
printf("%d=",n);
while(p!=NULL&&n!=0) {
if(n%p->data==0) {
count++;
if(count==1){
printf("%d",p->data);
}else{
printf("*%d",p->data);
}
n=n/(p->data);
} else {
p=p->next;
}
}
while(head!=NULL){//释放结点
p=head;
head=head->next;
free(p);
}
return 0;
}