1059. Prime Factors
来源:互联网 发布:淘宝首页导航怎么去掉 编辑:程序博客网 时间:2024/06/06 19:36
用素数筛
#include<iostream>#include<vector>#include<utility>using namespace std;const int N=10000;vector<bool>isp(N,true);long x,p=2;vector<pair<int,int>>st;long nextp(long p){ for(++p;p<N;++p) if(isp[p]) return p;};int main(){ for(int i=2;i<N;++i) for(int j=2;i*j<N;++j) isp[i*j]=false; cin>>x; cout<<x<<'='; if(x<2)cout<<x; else { while(x!=1) { if(x%p==0) { int cnt=0; while(x%p==0)++cnt,x/=p; st.push_back(make_pair(p,cnt)); } p=nextp(p); } for(int i=0;i<st.size();++i) { if(i)cout<<'*'; cout<<st[i].first; if(st[i].second!=1) cout<<'^'<<st[i].second; } } return 0;}
0 0
- 1059. Prime Factors
- 1059. Prime Factors (25)
- 1059. Prime Factors (25)
- PAT 1059. Prime Factors
- 1059. Prime Factors
- 1059. Prime Factors (25)
- 1059. Prime Factors
- 1059. Prime Factors (25)
- 1059. Prime Factors (25)
- PAT 1059. Prime Factors
- 1059. Prime Factors (25)
- 1059.Prime Factors
- 1059. Prime Factors (25)
- 1059. Prime Factors
- 1059. Prime Factors (25)
- 1059. Prime Factors (25)
- 1059. Prime Factors (25)
- 1059. Prime Factors (25)
- Direct3D 9 入门例子程序 圆锥体
- 学习Java的建议
- linux tomcat
- 旧版本uboot对ext4文件系统格式的支持
- Java实现双向链表
- 1059. Prime Factors
- 先吃个饭法规的厂房工程规划法换个房间和国际化
- Linux php/php-fpm 安装,配置
- oracle with使用
- 地方规定法规电饭锅电饭锅电饭锅地方高
- 谁知道撒地方撒大师大师大师大师
- Unique Binary Search Tree
- 1750: [Usaco2005 qua]Apple Catching (动态规划)
- JQuery,ajax同步异步设置潭