Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
7332 邓小龙 寻找绝对素数 C++ Accepted 6 MS 264 KB 859 2025-04-19 15:46:52

Tests(10/10):


Code:

//将1个数反转,判断这个反转的数是否为素数,同时不反转是不是素数 #include<bits/stdc++.h> using namespace std; //判断x是否为素数 bool Isprime(int x){ if(x<2) return false;//小于2的都是非素数 for(int i=2;i<=sqrt(x);i++){ if(x%i==0) return false; } return true; } int rev(int x){ int n=x; int ans=0; //12345-> 5,1234 -> 54, 123-> 543,12 -> 5432,1-> 54321,0 //*10+个位,降位 while(n!=0){ ans=ans*10+n%10; n/=10; } return ans; } int main(){ int m,n; bool f=false; cin>>m>>n; for(int i=m;i<=n;i++){ if(Isprime(i)&&Isprime(rev(i))){ if(f==false) cout<<i; else cout<<","<<i; f=true; } } if(f==false) cout<<"No"<<endl; return 0; }