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小素数 】 打表问题的更多相关文章

  1. BZOJ 3181([Coci2012]BROJ-最小质因子为p的第k小素数)

    3181: [Coci2012]BROJ Time Limit: 10 Sec   Memory Limit: 64 MB Submit: 26   Solved: 7 [ Submit][ Stat ...

  2. [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 ...

  3. [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 ...

  4. Leetcode 668.乘法表中第k小的数

    乘法表中第k小的数 几乎每一个人都用 乘法表.但是你能在乘法表中快速找到第k小的数字吗? 给定高度m .宽度n 的一张 m * n的乘法表,以及正整数k,你需要返回表中第k 小的数字. 例 1: 输入 ...

  5. LeetCode:乘法表中的第K小的数【668】

    LeetCode:乘法表中的第K小的数[668] 题目描述 几乎每一个人都用 乘法表.但是你能在乘法表中快速找到第k小的数字吗? 给定高度m .宽度n 的一张 m * n的乘法表,以及正整数k,你需要 ...

  6. Java实现 LeetCode 668 乘法表中第k小的数(二分)

    668. 乘法表中第k小的数 几乎每一个人都用 乘法表.但是你能在乘法表中快速找到第k小的数字吗? 给定高度m .宽度n 的一张 m * n的乘法表,以及正整数k,你需要返回表中第k 小的数字. 例 ...

  7. LeetCode 378. 有序矩阵中第K小的元素(Kth Smallest Element in a Sorted Matrix) 13

    378. 有序矩阵中第K小的元素 378. Kth Smallest Element in a Sorted Matrix 题目描述 给定一个 n x n 矩阵,其中每行和每列元素均按升序排序,找到矩 ...

  8. hdu 5104 素数打表水题

    http://acm.hdu.edu.cn/showproblem.php?pid=5104 找元组数量,满足p1<=p2<=p3且p1+p2+p3=n且都是素数 不用素数打表都能过,数据 ...

  9. SPOJ-COT-Count on a tree(树上路径第K小,可持久化线段树)

    题意: 求树上A,B两点路径上第K小的数 分析: 同样是可持久化线段树,只是这一次我们用它来维护树上的信息. 我们之前已经知道,可持久化线段树实际上是维护的一个前缀和,而前缀和不一定要出现在一个线性表 ...

随机推荐

  1. .net core nlog记录日志

    1.通过nuget 查找 下载 NLog.Extensions.Logging 2.配置nlog.config文件 <?xml version="1.0" encoding= ...

  2. 面向对象的特性-利用prototype为类创建静态成员

    —————————————————————————— <script type="text/javascript">            //用function模拟一 ...

  3. The List ADT

    1.Definiation A list is a sequence.  a0, a1,a2,..., aN (N>0) 2.Character For any list except the ...

  4. 第5章 字符串----char与String

    1.java有8种基本数据类型: 数值型:整数类型(byte,short,int,long) :浮点类型(float,double) 字符型:char  布尔型:true,false 2.char:  ...

  5. User.java 实体类 带 数据库字段模板

    package com.tgb.web.controller.entity; import javax.persistence.Column; import javax.persistence.Ent ...

  6. 转 Apache Ant 实现自动化部署

    Apache Ant 实现自动化部署 Apache Ant 实现自动化部署 http://www.netkiller.cn/journal/java.ant.html Mr. Neo Chen (陈景 ...

  7. jsp提交表单问题

    以form形式提交的话 String usernameInForm = hreq.getParameter("username");String passwordInForm = ...

  8. echarts学习总结(一):图表溢出窗口,图表数据窗口显示不全

    如上图所示:echarts图形左面的数据没有完全显示 只需在option中定义一下grid,例如:                                                gri ...

  9. Hibernate 系列教程3-单表操作

    工程截图 hibernate.cfg.xml <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Conf ...

  10. Android实现GIF图片解码与播放

    Android实现GIF图片解码与播放 如何在Android中播放GIF图片呢?如果直接按以前的方法,分解图片,可能相对比较麻烦. 今天给大伙介绍一种新的方式,构造自己的Android图片解码帮助类, ...