c++:
#include<iostream>
#include<cmath>
using namespace std;
bool is_prime(int n){
if(n < 2){
return false;
}
for(int i = 2; i <= sqrt(n);i++){
if(n % i == 0){
return false;
}
}
return true;
}
int main(){
int n;
while(cin >> n){
int m = n /2;
while(m > 1){
if(is_prime(m) && is_prime(n - m)){
cout << m << endl;
cout << n - m << endl;
break;
}else{
m = m - 1;
}
}
}
return 0;
}
python:
import math
def is_prime(n):
if n < 2:
return False
for i in range(2,int(math.sqrt(n)+1)):
if(n % i == 0):
return False
return True
while True:
try:
n = int(input())
m = n // 2
while m >= 2:
if is_prime(m) and is_prime(n - m):
print(m)
print(n-m)
break
else:
m -= 1
except:
break
|