素数筛法
来源:互联网 发布:node什么意思 编辑:程序博客网 时间:2024/05/16 09:20
J - Largest prime factor
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64uDescription
Everybody knows any number can be combined by the prime number.
Now, your task is telling me what position of the largest prime factor.
The position of prime 2 is 1, prime 3 is 2, and prime 5 is 3, etc.
Specially, LPF(1) = 0.
Now, your task is telling me what position of the largest prime factor.
The position of prime 2 is 1, prime 3 is 2, and prime 5 is 3, etc.
Specially, LPF(1) = 0.
Input
Each line will contain one integer n(0 < n < 1000000).
Output
Output the LPF(n).
Sample Input
12345
Sample Output
01213
#include<stdio.h>#include<math.h>#include<string.h>#include<algorithm>#include<map>using namespace std;int a[1000001]={0};map<int,int>m;void prime1(){ int p=1,i,j; for(i=2;i<=1000000;i++)//从2开始,知道2是素数 {if(a[i]==0)//如果是素数 {for(j=i;j<=1000000;j+=i)//从 j=i开始,因为此题需要不断更新数据,更节省时间的方法直接从i*i开始 {a[j]=p;//标记把此素数的 倍数 }p++;}}}int main(){ prime1();int n,flag,i,j;while(~scanf("%d",&n)){ if(n==1) printf("0\n"); else { printf("%d\n",a[n]);}}}
阅读全文
0 0
- 又见素数(素数筛法)
- nyoj 26 孪生素数 素数筛法
- HDU 4548 美素数 // 素数筛法
- 素数判断和素数筛法
- 素数筛法-----》大规模的判断素数
- 素数筛(筛选法求素数)
- 素数筛选法(素数筛)
- 森德拉姆素数筛法
- 素数筛法
- 素数筛法
- 筛法素数表
- 筛素数法
- POJ2262 素数筛法
- POJ3306 素数筛法
- 素数筛法
- 素数筛法
- 素数筛法
- 【数学】素数筛法
- 抽象类和接口的区别
- 如何分辨python语言中列表、元组的区别
- HTML整理1
- 第一篇CSDN博客
- Leetcode Single Number
- 素数筛法
- 未能加载文件或程序集“ICSharpCode.SharpZipLib, Version=0.86.0.518, Culture=neutral, PublicKeyToken=1b03e6acf116
- Yahoo军规-前端性能优化
- MongoDB实战经验
- ==与equals的区别
- winform j简单增删改查询
- 油漆写字
- 错误的警告
- DataBinding