1 #include<cmath> 2 #include<cstdio> 3 #include<algorithm> 4 const int MAXN = 1000; 5 6 int num[MAXN << 1],cnt = 0; 7 int bp[MAXN],prime[MAXN]; 8 bool flag = false; 9 10 inline void makep(int n) 11 { 12 bp[1] = true; 13 int cnt = 0; 14 for(int i = 2;i <= n;++ i) 15 { 16 if(!bp[i]) prime[++ cnt] = i; 17 for(int j = 1;j <= cnt;++ j) 18 { 19 if(prime[j]*i > n) break; 20 bp[i*prime[j]] = true; 21 if(i%prime[j] == 0) break; 22 } 23 } 24 } 25 26 void solve(int a) 27 { 28 if(!bp[a]) 29 { 30 num[a] ++; 31 cnt ++; 32 flag = true; 33 return; 34 } 35 for(int i = 2;i*i <= a;++ i) 36 { 37 if(flag) return; 38 if(!bp[i] && a%i == 0) 39 { 40 num[i] ++; 41 cnt ++; 42 solve(a/i); 43 } 44 } 45 } 46 47 int main() 48 { 49 int a; 50 scanf("%d",&a); 51 makep(a+1); 52 solve(a); 53 for(int i = 1;i <= a;++ i) 54 while(num[i]) 55 printf("%d ",i),num[i] --; 56 /* for(int i = 1;i <= a;++ i) 57 if(num[i]) 58 while(a%i == 0) 59 printf("%d ",i),a/=i;*/ 60 return 0; 61 }
时间: 2024-10-12 19:41:29