当前位置:网站首页>Template_ Euclidean sieve_ prime number
Template_ Euclidean sieve_ prime number
2022-07-18 13:20:00 【This question AC sleep again】
//
#include<bits/stdc++.h>
using namespace std;
const int N=1e8+9;
int prime[N+5];
bool judge[N+5];
void sieve()
{
memset( prime,0,sizeof( prime ) );
memset( judge,0,sizeof( judge ) );
int i,j,cnt=1;
for( i=2;i<N-5;i++ )
{
if( judge[i]==0 ) prime[cnt++]=i;
for( j=1;j<cnt && i<N/prime[j];j++ )
{
judge[i*prime[j]]=1;
if( i%prime[j]==0 ) break;
}
}
}
int main()
{
sieve();
int n,q,x;
while( cin>>n>>q )
{
while( q-- )
{
scanf( "%d",&x );
printf( "%d\n",prime[x] );
}
}
return 0;
}边栏推荐
- [machine learning] decision tree
- What is the ECS framework? Explain + practice to get you started ECS framework
- Go: 关于 gRPC
- 剑指 Offer 27. 二叉树的镜像
- [programming training 10] tic tac toe chess + password strength level
- 【HBZ分享】UDP协议讲解
- Implementation of MCU stack backtracking debugging principle based on gd32 c10x
- SSH Remote port forwarding
- Golang empty interface
- 傲梅輕松克隆系統盤備份
猜你喜欢
随机推荐
Batch stream fusion upgrade: Apache Flink 1.15.0 releases pulsar Flink sink connector
【HBZ分享】TCP协议讲解
端口轉發工具 rinetd
Dongfang selects the traffic password behind the explosion
160_ Skills_ Power Bi new function - calculate working days
金仓数据库 KingbaseES SQL 语言参考手册 (3.1.1.9. 网络地址类型)
[machine learning] random forest
Kingbasees SQL language reference manual of Jincang database (3.1.2. domain type)
Memory management page properties
【编程强训10】井字棋+密码强度等级
示波器的带宽介绍
What is the ECS framework? Explain + practice to get you started ECS framework
MATLAB学习第二天(基础语法、变量、命令以及新建自己文件)
Thesis reading: Pyramid scene parsing network
洛谷_P3383 【模板】线性筛素数_欧氏筛筛素数
社区峰会|Pulsar Summit 旧金山峰会议题亮点曝光!
【编程强训5】 连续最大和+统计回文
Kingbasees SQL language reference manual of Jincang database (3.1.1.9. network address type)
Mgre/ospf comprehensive experiment
傲梅轻松克隆系统盘备份









