大佬们,为什么第一个总是WA
查看原帖
大佬们,为什么第一个总是WA
354157
Sophon_楼主2020/7/26 14:31
#include <bits/stdc++.h>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int f(int x){
	int j=2;
	if(x==2) return 1;
	while(j<=sqrt(x)&&x%j!=0)
		j++; 
	if(x%j==0)
		return 0;	
	else
		return 1;
}
int main(int argc, char** argv) {
	int n,a[1000]={0};
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<n;i++){
		if(f(a[i])) cout<<a[i]<<" ";
	}
	return 0;
}

2020/7/26 14:31
加载中...