随笔 - 531  文章 - 0  评论 - 3  阅读 - 10215 

 

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

复制代码
#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   towboat  阅读(14)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
点击右上角即可分享
微信分享提示