题目链接:https://pintia.cn/problem-sets/994805260223102976/problems/994805309963354112
题解:
1 #include<iostream> 2 #include<math.h> 3 using namespace std; 4 5 bool Is_Prime(int n){ 6 if (n < 2) return false; 7 for (int i = 2; i <= sqrt(n); i++){ 8 if (n%i == 0) return false; 9 } 10 return true; 11 } 12 13 int main(){ 14 int M,N; 15 cin>>M>>N; 16 int count=0,k=0; 17 for(int i=2;;i++){ 18 if(Is_Prime(i)){ 19 count++; 20 if(count>=M&&count<=N){ 21 cout<<i;k++; 22 if(k%10==0) cout<<endl; 23 else if(count!=N) cout<<" ";//最后一个不能有空格 24 else{} 25 } 26 if(count>N) break;//for循环结束的条件 27 } 28 } 29 return 0; 30 }
转载于:https://www.cnblogs.com/Gzu_zb/p/9373174.html
原文链接:https://blog.csdn.net/weixin_30342827/article/details/98460822
本站声明:网站内容来源于网络,如有侵权,请联系我们,我们将及时处理。
还没有人抢沙发呢~