文章

81

粉丝

0

获赞

282

访问

11.0k

头像
输出素数 题解:
P2003 重庆大学机试题
发布于2025年3月15日 21:26
阅读数 86

#include<bits/stdc++.h>
using namespace std;
int i;
bool shu(int x){
	for(i=2;i<=sqrt(x);i++){
		if(x%i==0){
			return false;
		}
	}
	return true;
}

int main(){
	int n1,n2,j,index=0;
	cin>>n1>>n2;
	for(j=n1;j<=n2;j++){
		if(shu(j)){
		   cout<<j<<" ";
		    index++;
		   if(index==5){
			   cout<<endl;
			   index=0;
		   }
		}
	}

}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发