题解 | #素数对#
素数对
https://www.nowcoder.com/practice/c96d6acc025541ffb79c579688f8d003
#include <iostream>
using namespace std;
bool isZS(int num){
if(num<5) return num==2||num==3;
if(num%2 ==0) return false;
for(int i=3;i<(num/2+1);i=i+2){
if(num%i==0) return false;
}
return true;
}
int main(){
int num;
while(cin>>num){
int count =0;
count ++;
}
cout<<count;
}
return 0;
}
using namespace std;
bool isZS(int num){
if(num<5) return num==2||num==3;
if(num%2 ==0) return false;
for(int i=3;i<(num/2+1);i=i+2){
if(num%i==0) return false;
}
return true;
}
int main(){
int num;
while(cin>>num){
int count =0;
for(int i=3;i<(num/2+1);i=i+2){ //i+2去除偶数情况,num/2 去除重复情况。+1 则避免/2为奇数不进入判断发生
if(isZS(i)&&isZS(num-i)) count ++;
}
cout<<count;
}
return 0;
}