Problem:
Pair of Primes

We arrange the numbers between 1 and N (1 <= N <= 10000) in increasing
order and decreasing order like this:

1 2 3 4 5 6 7 8 9 . . . N
N . . . 9 8 7 6 5 4 3 2 1

Two numbers faced each other form a pair. Your task is to compute the number of pairs P such that both
numbers in the pairs are prime.

Input

Input contains several test cases. Each test case consists of an integer N in
one line.

Output

For each line of input, output P .

Sample Input

1
4
7
51

Output for the Sample Input

0
2
2
6

Solution in C++ (judge verdict: Accepted)

#include <bits/stdc++.h>

#define reps(v, f, l) for (int v = (f), v##_ = (l); v < v##_; ++v)
#define rep(v, n) reps(v, 0, n)
#define lep(v, n) reps(v, 1, n + 1)

using namespace std;

typedef long long int lint;

static inline int in(){ int x; scanf("%d", &x); return x; }
static inline lint inl(){ lint x; scanf("%lld", &x); return x; }
template<typename T> void show(T& a, char del='\n', char last='\n'){ rep(i, a.size() - 1) cout << a[i] << del; cout << a[a.size() - 1] << last; }

struct Sieve {
  const int size;
  vector<bool> sieve;
  Sieve(int size) : size(size), sieve(size + 1, true) {}
  void build(){
    for (int i = 2; i * i <= size; ++i){
      for (int j = i * i; j <= size; j += i){
        sieve[j] = false;
      }
    }
    sieve[0] = false;
    sieve[1] = false;
  }
  bool isPrime(int n){
    return sieve[n];
  }
};

int main()
{
  Sieve s(10000);
  s.build();
  int n;
  while (~scanf("%d", &n)){
    int count = 0;
    lep(i, n){
      if (s.isPrime(i) && s.isPrime(n - i + 1)){
        count++;
      }
    }
    cout << count << endl;
  }
  return 0;
}