幻影素数简单算法
#include<iostream>
#include<cmath>
using namespace std;
bool panduan(int i) {
for (int j = 2; j < i / 2; j++) {
if (i % j == 0) {
return false;
}
}
return true;
}
int sum1= 0;
void huanwei(int i) {
int a, b, c ,sum2;
a = i / 100;
b = (i % 100) / 10;
c = i % 10;
sum2 = c * 100 + b * 10 + a;
if (i != sum2 && panduan(sum2)) {
cout <<"幻影素数对:"<< i <<" "<<sum2<<endl;
sum1++;
}
//cout << endl;
}
int main() {
int a = 100, b = 999,sum=0;
for (int i = a; i <= b; i++) {
sum = 0;
for (int j = 1; j <= i; j++) {
if (i % j == 0) {
sum++;
}
}
if (sum == 2) {
//cout << i << " ";
huanwei(i);
}
}
cout << sum1 << endl;
}
祝每天开心
评论已关闭