1168: mxh对lfx的询问(前缀和+素数表)

时间:2023-03-10 06:49:06
1168: mxh对lfx的询问(前缀和+素数表)

题目描述:

AS WE ALL KNOW, lfx是咱们组的神仙,但是mxh想考一考lfx一个简单的问题,以此看一下lfx到底是不是神仙。但是lfx要准备补考,于是请你来帮忙回答问题:

给定一个整数N,和N个整数ai(1<=i<=n),mxh有n个询问,即第i个询问(1<=i<=n)是数组a从1~i这i个数中,奇数的个数是否是一个质数?< span="">

如果是请输出”YES”,没有引号。反之输出”NO”。

正如你想的那样,你输出有N个输出。

数据范围:

1<=n<=1e6

1<=ai<=1e6

非常easy的一个题目吧,为什么没人过,,如果a[i] 是奇数就把a[i]赋值为1,否则赋值为0。然后求a[i]数组的前缀和,

预处素数表之后,1~n扫一下前缀和,如果是质数就输出YES反而反之就好了。题目真没什么可以说的。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define rt return
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d\n",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=;while(b){if(b%)ans=ans*a%MOD;a=a*a%MOD;b/=;}return ans;}
inline void getInt(int* p);
const int maxn=;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
int n;
int a[maxn];
int sum[maxn];
const int N = 1e7+;
bool noprime[N+];// true -> 不是素数
vector <int> p;
void getPrime()
{
// 华丽的初始化
memset(noprime,false,sizeof(noprime));
p.clear(); int m=(int)sqrt(N+0.5);
// 多姿的线性筛
for(int i=;i<=m;i++)
{
if(!noprime[i])
{
for(int j=i*i;j<=N;j+=i)
{
noprime[j] = true;
}
}
}
noprime[]=;
// // 把素数加到vector里
// for(int i=2;i<=maxn;i++)
// {
// if(!noprime[i])
// {
// p.push_back(i);
// }
// }
// //返回vector的大小
// return p.size(); }
int main()
{
// freopen("D:\\common_text\\code_stream\\in.txt","r",stdin);
// freopen("D:\\common_text\\code_stream\\out.txt","w",stdout);
getPrime();
scanf("%d",&n);
repd(i,,n)
{
scanf("%d",&a[i]);
if(a[i]&)
{
a[i]=;
}else
{
a[i]=;
}
sum[i]=sum[i-]+a[i];
}
repd(i,,n)
{
if(noprime[sum[i]])
{
printf("NO\n");
}else{
printf("YES\n");
}
}
return ;
} inline void getInt(int* p) {
char ch;
do {
ch = getchar();
} while (ch == ' ' || ch == '\n');
if (ch == '-') {
*p = -(getchar() - '');
while ((ch = getchar()) >= '' && ch <= '') {
*p = *p * - ch + '';
}
}
else {
*p = ch - '';
while ((ch = getchar()) >= '' && ch <= '') {
*p = *p * + ch - '';
}
}
}