按照题意的要求逐渐求解:
#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; int prime[10]={2,3,5,7,11,13,17,19,23}; char zhishu[10][40]={"2","2*3","2*3*5","2*3*5*7","2*3*5*7*11","2*3*5*7*11*13", "2*3*5*7*11*13*17","2*3*5*7*11*13*17*19","2*3*5*7*11*13*17*19*23"};//vector<int> int mul[10]; int xishu[10]; int main() { int i,n; mul[0]=prime[0]; for(i=0;i<8;i++) { mul[i+1]=mul[i]*prime[i+1]; } while(scanf("%d",&n)!=EOF&&n) { int m=n; memset(xishu,0,sizeof(xishu)); for(i=8;i>=0;i--) { if(mul[i]<=n) { xishu[i]=n/mul[i]; n%=mul[i]; } //printf(""); } i=0; printf("%d =",m); if(m&1)printf(" 1"); else { while(!xishu[i])i++; printf(" %d*%s",xishu[i],zhishu[i]); i++; } for(;i<9;i++) { if(xishu[i]) printf(" + %d*%s",xishu[i],zhishu[i]); } printf("\n"); } return 0; }