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 <stdio.h>

int prime[10001];
void setprime(void){
    int i,o;
    for(i=4;i<=10000;i+=2)
        prime[i]=1;
    for(i=3;i*i<=10000;i+=2)
        if(!prime[i])
            for(o=i*2;o<=10000;o+=i)
                prime[o]=1;
    prime[1]=1;
}
int main(void){
    int num,sum,c;
    setprime();
    for(;c=1,sum=0,scanf("%d",&num)!=EOF;){
        for(;num;num--,c++)
            if(prime[num]==0&&prime[c]==0)
                sum++;
        printf("%d\n",sum);
    }
    return 0;
}