文章

81

粉丝

2

获赞

494

访问

9.5k

头像
素数 题解:
P1375 北京航空航天大学机试题
发布于2026年3月15日 15:17
阅读数 71

#include <iostream>
using namespace std;

bool isPrime(int x){
    if(x < 2) return false;
    for(int i = 2; i * i <= x; i++){
        if(x % i == 0)
            return false;
    }
    return true;
}

int main(){
    int n;

    while(cin >> n){
        bool res = true;

        for(int i = 1; i < n; i++){
            if(isPrime(i) && i%10==1){
                if(!res) cout << ' ';
				cout << i;
                res = false;
            }
        }

        if(res)
            cout << -1;

        cout << endl;
    }

    return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发