【第k小素数 】 打表问题
Prime Number
TimeLimit: 1 Second MemoryLimit: 32 Megabyte
Totalsubmit: 399 Accepted: 88
Description
We know that the number of prime numbers is countless. Now we want to know the kth small prime number.
Input
Input contains multiple test cases. Each test case contains an integer k.(1<=k<=10^5)
Output
Print the kth small prime number.
Sample Input
1
2
4
Sample Output
2
3
7
#include <iostream> #include <stdio.h> #include <math.h> #include <string.h> #define maxn 10000000 using namespace std; ]; ]; int num; void fun() { int limt=sqrt(maxn+0.0); int i,j; num=; pre[num++]=; memset(p,,sizeof(p)); ;i<=maxn;i+=)p[i]=; ;i<=limt;i+=) { if(p[i])continue; pre[num++]=i; ; } for(;i<=maxn;i++)if(!p[i])pre[num++]=i; } int main() { //freopen("in.txt","r",stdin); fun(); int n; while(cin >> n) { cout << pre[n-] << endl; } ; }
【第k小素数 】 打表问题的更多相关文章
- BZOJ 3181([Coci2012]BROJ-最小质因子为p的第k小素数)
3181: [Coci2012]BROJ Time Limit: 10 Sec Memory Limit: 64 MB Submit: 26 Solved: 7 [ Submit][ Stat ...
- [LeetCode] Kth Smallest Number in Multiplication Table 乘法表中的第K小的数字
Nearly every one have used the Multiplication Table. But could you find out the k-th smallest number ...
- [Swift]LeetCode668. 乘法表中第k小的数 | Kth Smallest Number in Multiplication Table
Nearly every one have used the Multiplication Table. But could you find out the k-th smallest number ...
- Leetcode 668.乘法表中第k小的数
乘法表中第k小的数 几乎每一个人都用 乘法表.但是你能在乘法表中快速找到第k小的数字吗? 给定高度m .宽度n 的一张 m * n的乘法表,以及正整数k,你需要返回表中第k 小的数字. 例 1: 输入 ...
- LeetCode:乘法表中的第K小的数【668】
LeetCode:乘法表中的第K小的数[668] 题目描述 几乎每一个人都用 乘法表.但是你能在乘法表中快速找到第k小的数字吗? 给定高度m .宽度n 的一张 m * n的乘法表,以及正整数k,你需要 ...
- Java实现 LeetCode 668 乘法表中第k小的数(二分)
668. 乘法表中第k小的数 几乎每一个人都用 乘法表.但是你能在乘法表中快速找到第k小的数字吗? 给定高度m .宽度n 的一张 m * n的乘法表,以及正整数k,你需要返回表中第k 小的数字. 例 ...
- LeetCode 378. 有序矩阵中第K小的元素(Kth Smallest Element in a Sorted Matrix) 13
378. 有序矩阵中第K小的元素 378. Kth Smallest Element in a Sorted Matrix 题目描述 给定一个 n x n 矩阵,其中每行和每列元素均按升序排序,找到矩 ...
- hdu 5104 素数打表水题
http://acm.hdu.edu.cn/showproblem.php?pid=5104 找元组数量,满足p1<=p2<=p3且p1+p2+p3=n且都是素数 不用素数打表都能过,数据 ...
- SPOJ-COT-Count on a tree(树上路径第K小,可持久化线段树)
题意: 求树上A,B两点路径上第K小的数 分析: 同样是可持久化线段树,只是这一次我们用它来维护树上的信息. 我们之前已经知道,可持久化线段树实际上是维护的一个前缀和,而前缀和不一定要出现在一个线性表 ...
随机推荐
- KNN算法的补充
文本自动分类技术是文字管理的基础.通过快速.准确的文本自动分类,可以节省大量的人力财力:提高工作效率:让用户快速获得所需资源,改善用户体验.本文着重对KNN文本分类算法进行介绍并提出改进方法. 一.相 ...
- iosOC不可变数组遍历
NSArray * array = @[@"1",@"2",@"3"]; NSLog(@"%@",array); //1 ...
- Python logging模块使用记录
1.简单的将日志打印到屏幕 import logging logging.debug('This is debug message') logging.info('This is info messa ...
- 下拉的DIV+CSS+JS二级树型菜单
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 1213 How Many Tables 简单的并查集问题
my code: #include <cstdio>#include <cstring>#include<iostream>using namespace std; ...
- const放在函数前和函数后
class c { public: returnType functionName (parameter list) const; //这个函数不会修改类成员 const returnType fun ...
- shell脚本学习(二)
4.cat命令 1) cat -s 摆脱多余的空白行 2) cat -T 将制表符显示为^I 3) cat -n 显示行号 4) cat -b 跳过空白行,然后显示行号 ...
- Entity Framework中对存储过程的返回值的处理
很早就开始注意到EF了,但一直没有机会用,换了工作后,第一个项目就使用EF6进行开发. 项目不是很大,EF完全可以胜任. 但是开发过程中,难免还是会遇到一些复杂的运算,需要频繁访问数据库. 此时,想到 ...
- UIImageView的UserInteractionEnabled什么时候为no
UIImageView作为背景,但直接把按钮或者UITextField放在上面无法相应事件 特殊子类的覆盖 userInteractionEnabled属性默认值为YES,但UIView的一些子类中对 ...
- ubuntu下 编译Caffe的Matlab接口
一般情况下不愿意使用Caffe的Matlab接口,总觉得Linux版的Matlab很难配置,但是现在搞目标检测,得到的源码是使用的Caffe的Matlab接口,只能硬着头皮上了. (1)修改caffe ...