文章

4

粉丝

29

获赞

4

访问

2.0k

头像
素数 题解:
P1375 北京航空航天大学机试题
发布于2023年7月29日 16:05
阅读数 446

解法一:先求出10000以内所有素数,再筛选。

#include <bits/stdc++.h>
using namespace std;
#include <bits/stdc++.h>
using namespace std;
const int maxn=10005;
int prime[maxn];
void getPrime(){
    memset(prime,0,sizeof(prime));
    for(int i=2;i<=maxn;i++){
        if(!prime[i])
            prime[++prime[0]]=i;
        for(int j=1;j<=prime[0]&&prime[j]*i<=maxn;j++){
            prime[prime[j]*i]=1;
            if(i%prime[j]==0)
                break;
        }
    }
}
int main(){
    int n;
    while(cin>>n){
        getPrime();
       &...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发