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 JAVA (judge verdict: Accepted)

import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n,i,j,count;
		boolean p[]=new boolean[10001];
		//
		Arrays.fill(p, true);
		p[0]=p[1]=false;
		for(i=2;i<=10000;i++){
			if(p[i])
				for(j=2;i*j<=10000;j++){
					p[i*j]=false;
				}
		}//
		while(sc.hasNext()){
			n=sc.nextInt();
			count=0;
			for(i=1;i<=n;i++){
				//System.out.println(i+""+p[i]+" "+(n-i+1)+""+p[n-i+1]);
				if(p[i] && p[n-i+1]) count++;
			}
			System.out.println(count);
		}//
	}
}