原理:如果一个数是素数,它的倍数就是合数。

 1 #include<iostream>
 2 using namespace std;
 3 #include<cmath>
 4 
 5 bool sushu[210000000];
 6 int n;
 7 int main()
 8 {
 9     sushu[1]=sushu[0]=1;
10     cin>>n;
11     for(int i=2;i<=sqrt(n);++i)
12     {
13         if(sushu[i]==0)for(int j=i*i;j<=(n);j+=i)
14         {
15             sushu[j]=1;
16         }
17     }
18     if(sushu[n])cout<<"no";
19     else cout<<"yes";
20     return 0;
21  } 

 

相关文章:

  • 2022-12-23
  • 2021-06-09
猜你喜欢
  • 2021-08-31
  • 2021-11-12
相关资源
相似解决方案