题目大意:定义n个数为幸运数字,一共有n批人,设第i批人有x个,则它们会依次取走余下的x的倍数中最小的x个,问哪些人去走了幸运数字
因为幸运数字大小都是1000000以内的,所以我们只需要维护1000000以内的数取没取走以及以他们为约数都取到哪了,当新的取数操作开始时就暴力找,根据调和级数,所有数加起来一共只能NlogN步,所以时间复杂度是能保证的
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 1000010
using namespace std;
int now[N];
bool f[N];
int tot;
long long cnt,ans[N];
bool used[N];
int main()
{
int n,m;
int j,x,y;
long long i;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%d",&x);
f[x]=true;
}
scanf("%d",&m);
while(m--)
{
scanf("%d",&x);
for(i=1;i<=x;i++)
{
now[x]+=x;
while(now[x]<=1000000&&used[now[x]]) now[x]+=x;
if(now[x]>1000000) break;
used[now[x]]=true;
if(f[now[x]]) tot++,ans[tot]=cnt+i;
}
cnt+=x;
}
printf("%d\n",tot);
for(i=1;i<=tot;i++)
printf("%lld\n",ans[i]);
}