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)

using System;
using System.Collections.Generic;

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1004


public class Test
{
	public static void Main()
	{
		while(true){
		  string str1 = Console.ReadLine();
		  if(str1 == null) break;
		  
		  int n = int.Parse(str1); 

		  //Console.WriteLine("???????????? N = {0} P = {1} Ai = {2}", n, p, a);
		  Console.WriteLine(calc(n));
		
		
		}

	}

  public static int calc(int n) {
	  if(n==1) return 0;
	  if(n==2) return 0;
	  if(n==3) return 1;
	  
	  int s = 0;
	  if((n%2)==0) {
        if(IsPrime(n-1)) {
	  	  s = 2;
	    }
	  } else {
	    for(int i=3; i<=(n/2); i+=2){
          if(IsPrime(i) && IsPrime(n+1-i)) s++;
	    }
 
        if(IsPrime((n/2)+1)) {
	  	s = 2*s+1;
	    } else {
	  	s = 2*s;
	    }
	  }



	  return s;
  }
  
  public static bool IsPrime(int num)
  {
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // ??¶??°????????????????????????

    double sqrtNum = Math.Sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // ?´???°??§?????????
            return false;
        }
    }

    // ?´???°??§??????
    return true;
  }
  

}