文章

31

粉丝

0

获赞

67

访问

6.4k

头像
素数 题解:
P1375 北京航空航天大学机试题
发布于2026年1月16日 21:05
阅读数 171

注意等于号sqrt

 

#include <stdio.h>  
#include <string.h>  
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;  

bool ss(int a){
    for(int i=2;i<=sqrt(a);i++){//注意等于号 
        if(a%i==0){
            return false;
        }
    }
    return true;
}

int main() {  
    int n;
    
    while(cin>>n){
        bool flag=false;
        for(int i=2;i<n;i++){
            if(ss(i)&&(i%10==1)){
                cout<<i<<" ";
                flag=true;
&nbs...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发