素数筛法
来源:互联网 发布:xperia touch 知乎 编辑:程序博客网 时间:2024/06/07 12:18
hdu 2.1.3
Largest prime factor
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5996 Accepted Submission(s): 1834Problem Description
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
Author
Wiskey
Source
HDU 2007-11 Programming Contest_WarmUp
Recommend
威士忌
#include<cstdio>int prim[1000005]= {0}; //全部初始化为0void init(){ int k; prim[1]=0; k=1; for(int i=2; i<1000000; i++) //素数筛法 if(prim[i]==0)//i是素数 { for(int j=i; j<1000000; j+=i) prim[j]=k; k++; }}int main(){ int n; init(); while(~scanf("%d",&n)) printf("%d\n",prim[n]);}素数筛法就是不标记本身,标记本身的倍数。
××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××××
以下为我碰到的一些素数题
How many prime numbers
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 10657 Accepted Submission(s): 3496Problem Description
Give you a lot of positive integers, just to find out how many prime numbers there are.
Input
There are a lot of cases. In each case, there is an integer N representing the number of integers to find. Each integer won’t exceed 32-bit signed integer, and each of them won’t be less than 2.
Output
For each case, print the number of prime numbers you have found out.
Sample Input
32 3 4
Sample Output
2
Author
wangye
Source
HDU 2007-11 Programming Contest_WarmUp
Recommend
威士忌
题意是找出素数的个数(最简单的)
<pre name="code" class="cpp">#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<cmath>using namespace std;#define N 100000000int a[N];int main(){ int n; while(~scanf("%d", &n)) { for(int i=0; i<n; i++) { scanf("%d", &a[i]); } int sum=0; for(int i=0; i<n; i++) { int sign=0; for(int j=2; j<=sqrt(a[i]*1.0); j++) { if(a[i]%j==0) { sign=1; break; } } if(sign==0) { sum++; //cout<<sum<<"**"<<endl; } } printf("%d\n", sum); }}
Largest prime factor
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 6009 Accepted Submission(s): 1840Problem Description
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
Author
Wiskey
Source
HDU 2007-11 Programming Contest_WarmUp
Recommend
威士忌
题意是找出找出一个数最大素因子在素数表的位置
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<cmath>using namespace std;#define N 1000000+5int prime[N]={0};void init(){ int k; prime[1]=0; k=1; for(int i=2; i<N; i++){ if(prime[i]==0){ for(int j=i; j<N; j+=i){ prime[j]=k; } k++; } }}int main(){ int n; init(); while(~scanf("%d", &n)){ printf("%d\n", prime[n]); }}
七夕节
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 5469 Accepted Submission(s): 1911Problem Description
七夕节那天,月老来到数字王国,他在城门上贴了一张告示,并且和数字王国的人们说:"你们想知道你们的另一半是谁吗?那就按照告示上的方法去找吧!"
人们纷纷来到告示前,都想知道谁才是自己的另一半.告示如下:
数字N的因子就是所有比N小又能被N整除的所有正整数,如12的因子有1,2,3,4,6.
你想知道你的另一半吗?
人们纷纷来到告示前,都想知道谁才是自己的另一半.告示如下:
数字N的因子就是所有比N小又能被N整除的所有正整数,如12的因子有1,2,3,4,6.
你想知道你的另一半吗?
Input
输入数据的第一行是一个数字T(1<=T<=500000),它表明测试数据的组数.然后是T组测试数据,每组测试数据只有一个数字N(1<=N<=500000).
Output
对于每组测试数据,请输出一个代表输入数据N的另一半的编号.
Sample Input
321020
Sample Output
1822
Author
Ignatius.L
Source
杭电ACM省赛集训队选拔赛之热身赛
Recommend
Eddy
题意是求一个数所有因子的和;
#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>#include<cmath>using namespace std;#define N 500000+5int pose[N];int n;void init(){ for(int i=1; i<N; i++){ pose[i]=1; } for(int i=2; i<N; i++){ for(int j=i+i; j<N; j+=i){ pose[j]+=i; //if(j==n) // printf("i:%d j:%d pose:%d\n", i, j, pose[j]); } }}int main(){init(); int t; scanf("%d", &t); while(t--){ //int n; scanf("%d", &n); if(n==1) {printf("0\n"); continue;} printf("%d\n", pose[n]); }}
0 0
- 又见素数(素数筛法)
- nyoj 26 孪生素数 素数筛法
- HDU 4548 美素数 // 素数筛法
- 素数判断和素数筛法
- 素数筛法-----》大规模的判断素数
- 素数筛(筛选法求素数)
- 素数筛选法(素数筛)
- 森德拉姆素数筛法
- 素数筛法
- 素数筛法
- 筛法素数表
- 筛素数法
- POJ2262 素数筛法
- POJ3306 素数筛法
- 素数筛法
- 素数筛法
- 素数筛法
- 【数学】素数筛法
- Uva 12096 The SetStack Computer
- 读芥川龙之介小说
- dlopen example
- iOS--UINavigationController学习笔记二
- EntityFramework错误处理
- 素数筛法
- 关于Android 添加系统级(java)服务和调用的编写实现说明
- hdu 1269 迷宫城堡 强连通分量分解
- String和string区别
- Python 基础 —— from __future__ import
- Java 中的反射
- 在mac上使用VMware Fusion安装windows连不上网问题
- Jenkins中使用ant管理Android应用开发生命周期
- java 泛型