素数筛选和合数分解
来源:互联网 发布:php内核源码分析 编辑:程序博客网 时间:2024/05/21 15:18
具体代码实现如下:
#include <iostream>#include <cstring>using namespace std;const int MAXN=100000;///MAXN的大小与题目规模有关int prime[MAXN+1];void getPrime(){ memset(prime,0,sizeof(prime)); for(int i=2;i<=MAXN;i++) { if(!prime[i]) prime[++prime[0]]=i; for(int j=1;j<=prime[0]&&prime[j]<=MAXN/i;j++) { prime[prime[j]*i]=1; if(i%prime[j]==0) break; } }}long long factor[100][2];int fatCnt;int getFactors(long long x){ fatCnt=0; long long tmp=x; for(int i=1;prime[i]<=tmp/prime[i];i++) { factor[fatCnt][1]=0; if(tmp%prime[i]==0) { factor[fatCnt][0]=prime[i]; while(tmp%prime[i]==0) { factor[fatCnt][1]++; tmp/=prime[i]; } fatCnt++; } } if(tmp!=1) { factor[fatCnt][0]=tmp; factor[fatCnt++][1]=1; } return fatCnt;}int main(){ long long n; getPrime(); cin>>n; int num=getFactors(n); for(int i=0;i<num;i++) { cout<<factor[i][0]<<" "<<factor[i][1]<<endl; } return 0;}
0 0
- 素数筛选和合数分解
- 素数筛选和合数分解
- 邝斌的ACM模板(素数筛选和合数分解)
- 素数筛选 素数分解
- 筛选法求素数表,并标记素数位置和合数最大质数位置 HOJ 2136
- NUC1019 数素数【素数筛选法】
- Miller_rabin & pollard_rho 快速素数检和合数因式分解
- Find Terrorists(素数筛选+素因子分解)
- 数论 素数筛选法与整数的素因子分解
- 数论--素数筛选法与整数的素因子分解
- poj 3421 X-factor Chains 素数筛选 因子分解
- 将一个数分解为素数乘积
- 素数筛选(判断<MAXN的数是否是素数)
- 判断是否为素数 + 分解质因数(利用了Miller_Rabin和素数筛选法)
- 素数筛选
- 筛选素数
- 素数筛选
- 筛选素数
- 牛客网刷题--剑指offer(从尾到头打印链表)
- 关于priority_queue
- VS中的路径宏 OutDir、ProjectDir、SolutionDir各种路径
- &和&& |和|| 区别
- BZOJ1336&1337:[Balkan2002]Alien最小圆覆盖
- 素数筛选和合数分解
- 通过Servlet理解MVC框架的基本实现原理
- linux查看日志命令
- RecyclerView的使用
- activity切换动画全局设定
- 访问中国天气网获取最近三天的数据
- 有序链表的归并
- 同时运行两个TOMCAT的配置
- Windows平台下一些好玩的技巧