#include<iostream> usingnamespacestd; intfind_prime(int *a, int length, int n); boolbinary_find(constint *a, int length, int from, int to, int target); intmain(){ int a[1000]; int n; cin >> n; int mid = n / 2; int count = find_prime(a, 1000, n); int num_couple = 0; for(int i = 2; i <= mid; i++) { if(binary_find(a, 1000, 0, count - 1, i) && binary_find(a, 1000, 0, count - 1, n - i)) num_couple += 1; } cout << num_couple; return0; }
intfind_prime(int *a, int length, int n) { int count = 0; bool flag = true; for(int i = 2; i < n; i ++) { for(int j = 2; j < i; j++) { if(i % j == 0) { flag = false; break; } } if(flag) a[count++] = i; flag = true; } return count; } boolbinary_find(constint* a, int length, int from, int to, int target) { while(from <= to) { int mid = (from + to) / 2; if(a[mid] > target) to = mid - 1; elseif(a[mid] < target) from = mid + 1; else returntrue; } returnfalse; }