题目地址:http://pat.zju.edu.cn/contests/pat-b-practise/1007
1 #include<stdio.h> 2 #include<math.h> 3 4 int i, j; 5 int num[100005]; 6 int n; 7 int count = 0; 8 int temp = 0; 9 int main() 10 { 11 scanf("%d", &n); 12 num[0] = 2; 13 num[1] = 3; 14 count = 2; 15 for( i = 4; i <= n; ++i ) 16 { 17 temp = 0; 18 for( j = 2; j <= sqrt(i); ++j ) 19 { 20 if( (i % j) == 0 ) 21 { 22 temp = 1; 23 break; 24 } 25 } 26 if( temp != 1 ) 27 { 28 num[count] = i; 29 ++count; 30 } 31 } 32 temp = 0; 33 for( i = 0; i < count - 1; ++i ) 34 { 35 if( (num[i+1] - num[i]) == 2 ) 36 ++temp; 37 } 38 printf("%d\n", temp); 39 return 0; 40 }