题目:
![](https://i-blog.csdnimg.cn/blog_migrate/11fe1186911ff8e342f66436dd0ba9dc.png)
C++实现:
#include<stdio.h>
#include<iostream>
#include<math.h>
using namespace std;
int is_prime(int n)
{
int m;
if (n <= 1)
return 0;
m = floor(sqrt(n) + 0.5); //防止数据太大溢出(int型)
for (int i = 2; i <= m; i++) //直接写m = sqrt(n),“.99999”会被直接截掉
{
if (n%i == 0)
return 0;
}
return 1;
}
int main()
{
int n;
cin >> n;
if (is_prime(n) == 1)
cout << "Yes" << endl;
else
cout << "No" << endl;
return 0;
}