想问一下那个n没有定义大小,后面怎么循环呢,还有init函数的意义是什么
代码如下:
#include<bits/stdc++.h>
using namespace std;
int s[10000],n;
int is_prime(int t)
{
for(int i=2;i*i<=t;i++)
if(t%i==0)return 0;
return 1;
}
void init()
{
for(int i=2;i<10000;i++)
if(is_prime(i))
s[n++]=i;
}
int main()
{
init();
int t;
cin>>t;
while(t--)
{
int ans=0;
int x;
cin>>x;
for(int i=0;i<n-1;i++)
for(int j=i+1;j<n;j++)
if(x==s[i]+s[j])
ans++;
cout<<ans<<endl;
}
return 0;
}