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: Time Limit Exceeded)

#include<stdio.h>

int prime(int n){
  int i;
  
  if((n!=2 && n%2==0)||n==1){
    return 0;
  }
  for(i=3;i<n;i++){
    if(n%i==0){
      return 0;
    }
    if(n/2<i){
      break;
    }
  }
  return 1;
}

int main(){
  int n,i,r;
  int a[10000];
  int b[10000];
  int c[10000];
  
  while(scanf("%d",&n)!=EOF){
    for(i=1;i<=n;i++){
      a[i-1]=i;
      b[i-1]=n-i+1;
      c[i-1]=0;
    }
    for(i=0;i<n;i++){
      c[i]=c[i]+prime(a[i]);
      c[i]=c[i]+prime(b[i]);
    }
    r=0;
    for(i=0;i<n;i++){
      if(c[i]==2){
	r++;
      }
    }
    printf("%d\n",r);
  }
  return 0;
}