题解 | #查找组成一个偶数最接近的两个素数#
查找组成一个偶数最接近的两个素数
https://www.nowcoder.com/practice/f8538f9ae3f1484fb137789dec6eedb9
#include <iostream> #include<math.h> using namespace std; //查找组成一个偶数最接近的两个素数 bool Judge(int x){ //判断是否为质数 if(x<2){ //小于2必定不是质数 return false; } int bound= sqrt(x); for(int i=2;i<=bound;i++){ if(x%i==0){ return false; } } return true; } int main() { int n; cin>>n; int temp=1,a=n/2,b=n/2; while(1){ if(Judge(a)&&Judge(b)){ cout<<a<<endl<<b; break; } a=n/2-temp; b=n/2+temp; temp+=1; } return 0; }