题解 | #查找组成一个偶数最接近的两个素数#
查找组成一个偶数最接近的两个素数
https://www.nowcoder.com/practice/f8538f9ae3f1484fb137789dec6eedb9
/* * @Description: If you get question about the code, contact me at **********. * @Author: pengjunxing * @Date: 2023-02-08 14:28:15 * @LastEditors: pengjunxing * @LastEditTime: 2023-02-08 14:42:25 */ #include<iostream> using namespace std; bool isprime(int num) { for(int i=2;i<num;i++) { if(num%i==0) { return false; } } return true; } int main() { int num; cin>>num; if((num<2)||(num%2!=0)) { return 0; } int n1; int n2; int gap=1000; for(int i =2;i<=num/2;i++) { if(isprime(i)&&isprime(num-i)) { if(num-i-i<gap) { n1=i; n2=num-i; } } } cout<<n1<<endl; cout<<n2; }