哈工大机试 素数判断 Easy *01负数非素数

基本思想:

不用打表,直接判断;

 

关键点:

无;

 

#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
using namespace std;

int m, n;

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

int main() {
	string s;
	while (cin >> n) {
		if (charge(n))
			cout << "yes" << endl;
		else
			cout << "no" << endl;
	}
	return 0;
}

  

posted @ 2020-03-04 11:11  暮云林凌  阅读(197)  评论(0)    收藏  举报