文章

17

粉丝

0

获赞

119

访问

4.6k

头像
素数 题解:
P1375 北京航空航天大学机试题
发布于2025年3月8日 20:54
阅读数 163

#include <iostream>
#include <cstring>
using namespace std;

const int maxm = 10005;
int p[maxm];

void ifsushu(){
    memset(p, 0, sizeof(p));  // 初始化所有数为素数
    for(long i = 2; i < maxm; i++){
        if(p[i]==0) p[++p[0]] = i;// 如果i是素数
            for(long j = 1; j<=p[0]&&i*p[j]<=maxm;j++){
                p[i*p[j]] = 1;
            }
    }
}

 


int main(){
    ifsushu();
    int a;
    while(cin >> a){
        int tmp = 0;
        for(int i = 2; p[i] < a; i++){
            if(p[i] % 10 == 1){  // 如果是素数且个位为1
     ...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发