求出最小质因数,然后做除法

#include <bits/stdc++.h>
using namespace std ; const int N=5e3+1;
 
 int vis[N],c[N],tot;
 int g[N];
 void init(int top){
     vis[1]=1;
     
     int i,j;
     for(i=2;i<=top;i++){
         if(!vis[i]) c[++tot]=i,g[i]=i;
         
        for(j=1;j<=tot&&i*c[j]<=top;j++){
             vis[i*c[j]]=1; g[i*c[j]]=c[j];
             if(i%c[j]==0) break;
        } 
     }
 }
 int st[N],hh;
 int main(){
     init(4e3);
     int i,x;
     while(cin>>x){
     hh=0;
    while(x>1) st[++hh]=g[x],x/=g[x];
    for(i=1;i<=hh;i++) cout<<st[i]<<' ';cout<<'\n';
    }
 }
 
 

 

posted on 2022-12-21 17:44  towboat  阅读(19)  评论(0)    收藏  举报