1411区间内的真素数2

终于有时间来改一改《1411区间内的真素数》http://www.cnblogs.com/tflsnoi/p/8026744.html这道题

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cmath>
 4 using namespace std;
 5 int m,n;
 6 int b[10000];
 7 //iss(int x)函数的功能:判断x是否是素数 
 8 bool iss(int x)
 9 {
10     for(int i=2;i*i<=x;i++)
11     {
12         if(x%i==0)return false;
13     }
14     return true;
15 }
16 
17 /*int dx(int n)的功能逆序输出数字*/
18 int dx(int n)
19 {
20   int s=0;
21   while(n>0)
22   {
23   s=s*10+n%10;
24   n/=10;
25   }
26  return s;
27 }
28 int main()
29 {
30     
31     int j=0;
32     cin>>m>>n;
33     bool iszss=true;
34     for(int i=m;i<=n;i++)
35     if(iss(i)&&iss(dx(i)))
36     {
37     
38         b[j++]=i;
39         iszss=false;
40     
41     }
42     if(!iszss){
43     for(int k=0;k<j-1;k++)cout<<b[k]<<",";
44     cout<<b[j-1];
45     }
46     else cout<<"No";
47     return 0;
48  } 

上面代码逻辑性更强。。。。。原来的代码比较乱

结果当然很理想

so,代码的逻辑性很重要。。。审题时最好把代码逻辑搞清楚。。。

原文地址:https://www.cnblogs.com/tflsnoi/p/8036383.html