解题思路:
从1到n将所有数筛一遍,枚举加数,如果这两个加数都是质数,那么方案数加1.
AC代码:
1 #include<cstdio> 2 3 using namespace std; 4 5 int n,ans; 6 bool vis[8000001]; 7 8 int main() 9 { 10 scanf("%d",&n); 11 for(int i = 2;i * i <= n; i++) 12 if(!vis[i]) { 13 for(int j = i * i;j <= n; j += i) 14 vis[j] = 1; 15 } 16 for(int i = 2;i <= n / 2; i++) 17 if(!vis[i] && !vis[n-i]) ans++; 18 printf("%d",ans); 19 return 0; 20 }