题解:P11056 Fire and Big
wwz1428572008 · · 题解
考试时写了一个
做法
维护对于每个
由于任意
代码
#include<iostream>
#include<cstdio>
#include<unordered_set>
using namespace std;
bool ok[500002];
bool w[500002];
unordered_set<int> s;
int read()
{
char ch=getchar();
int ret=0;
while(!isdigit(ch))
ch=getchar();
while(isdigit(ch))
{
(ret*=10)+=ch-'0';
ch=getchar();
}
return ret;
}
int main()
{
int t=read(),n=read();
int cur=0;
for(int i=1;i<=n;i++)
{
while(ok[cur%n]||w[cur%n])
{
w[cur%n]=0;
cur++;
}
ok[cur%n]=1;
s.insert(cur);
for(int j=1;j*j<n;j++)
w[(cur+j*j)%n]=1;
}
int x;
while(t--)
{
x=read();
if(s.count(x))
putchar('B');
else
putchar('F');
}
return 0;
}