素数回文
#include
#include
#include
#include
using namespace std;
int digits(long long num) {
int count = 0;
while(num != 0) {
num /= 10;
count++;
}
return count;
}
bool isprime(long long n) {
if (n <= 1) return false;
if (n <= 3) return true;
if (n % 2 == 0 || n % 3 == 0) return false;
for (long long i = 5; i * i <= n; i += 6) {
if (n % i == 0 || n % (i + 2) == 0)
return false;
}
return true;
}
int main() {
long long a, b = 0;
cin >> a;
int cnt = digits(a);
long long c = a / 10;
while (a > 0) {
b = b * 10 + a % 10;
a = a / 10;
}
long long e = pow(10, cnt);
long long j = c * e;
long long i = j + b;
if (isprime(i)) {
cout << "prime" << endl;
} else {
cout << "noprime" << endl;
}
return 0;
}
#include
#include
#include
#include
using namespace std;
int digits(long long num) {
int count = 0;
while(num != 0) {
num /= 10;
count++;
}
return count;
}
bool isprime(long long n) {
if (n <= 1) return false;
if (n <= 3) return true;
if (n % 2 == 0 || n % 3 == 0) return false;
for (long long i = 5; i * i <= n; i += 6) {
if (n % i == 0 || n % (i + 2) == 0)
return false;
}
return true;
}
int main() {
long long a, b = 0;
cin >> a;
int cnt = digits(a);
long long c = a / 10;
while (a > 0) {
b = b * 10 + a % 10;
a = a / 10;
}
long long e = pow(10, cnt);
long long j = c * e;
long long i = j + b;
if (isprime(i)) {
cout << "prime" << endl;
} else {
cout << "noprime" << endl;
}
return 0;
}
全部评论
相关推荐
点赞 评论 收藏
分享
点赞 评论 收藏
分享
11-13 16:29
门头沟学院 嵌入式软件工程师 点赞 评论 收藏
分享