【第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小的数 分析: 同样是可持久化线段树,只是这一次我们用它来维护树上的信息. 我们之前已经知道,可持久化线段树实际上是维护的一个前缀和,而前缀和不一定要出现在一个线性表 ...
随机推荐
- iOS tableView的系统分割线定格设置以及分割线自定制
一.关于分割线的位置. 分割线的位置就是指分割线相对于tableViewCell.如果我们要根据要求调节其位置,那么在iOS7.0版本以后,提供了一个方法如下: if ([self.tableView ...
- VBS基础篇 - 对象(1) - Class对象
VBS基础篇 - 对象(1) - Class对象 相信对JAVA有一定了解的朋友一定对类这个名词不陌生,但是大家可能没有想过在VBS中使用Class类吧,其实Class类在自动化测试中是相当常用的 ...
- 【转】PHP android ios相互兼容的AES加密算法
APP项目用户密码传输一直没有用HTTPS,考虑到用户的隐私暂时先用AES对密码加密,以后也可以用于手机端与服务端加密交互. PHP的免费版phpAES项目,手机端解码各种不对. 好不容易找了PHP ...
- td里的内容宽度自适应 及 鼠标放上显示标题div title
td里的内容自适应宽度, 用 width:100%控制 strRight+="<td bordercolor='#DEDEDE' width='500px' height='50px' ...
- freemarker中的list 前端模板
freemarker list (长度,遍历,下标,嵌套,排序)1. freemarker获取list的size : JavaArrayList<String> list = new Ar ...
- rndc 错误解决 和 远程配置
dc: connect failed: connection refusedrndc: connect failed: connection refused 解决办法:默认安装BIND9以后,是无法直 ...
- 如果更新包更新包现场,class文件更新过去,没有改变,及时删掉,照样能进那个模块的问题。
这是打更新包需要注意的问题: 带$的同名文件也需要copy过来打更新包,不能只更新一个class文件,找了1天的错误,简直日乐购.
- Parade
Parade time limit per test 1 second memory limit per test 256 megabytes input standard input output ...
- Python Django Learning Notes..
The first time I came across django was last month.. Since then I was considering it as the better c ...
- java数据结构之链表的实现
这个链表的内部是使用双向链表来表示的,但是并未在主函数中进行使用 /** * 链表 * 2016/4/26 **/ class LinkList{ Node head = new Node(); No ...