题解 | #素数回文#
素数回文
https://www.nowcoder.com/practice/d638855898fb4d22bc0ae9314fed956f
#include <iostream>
using namespace std;
#include <cmath>
long long int transint(int n){
int a[20];
int i=0,j,r;
long long int num=0,count;
while(n>0){
a[i++]=n%10;
n=n/10;
}
int h=0;
for(j=i-1;j>=1;j--){
r=h++;
count=a[j];
while(r>0){
count=count*10;
r--;
}
num +=count;
}
for(int k=0;k<i;k++){
r=h++;
count=a[k];
while(r>0){
count=count*10;
r--;
}
num +=count;
}
return num;
}
int main() {
int n;
int temp=0;
cin>>n;
long long int num=transint(n);
//开根号降低时间复杂度
for(long long int i=2;i<sqrt(num);i++){
if(num%i==0){
temp=1;
cout<<"noprime";
break;
}
}
if(temp==0)cout<<"prime";
}
// 64 位输出请用 printf("%lld")

查看22道真题和解析