题目
https://loj.ac/problem/2685
解题思路
代码
#include<cstdio>
#define rep(i,x,y) for(register int i=x;i<=y;++i)
using namespace std;
const int N=10000000,M=100003;
int g[N+1],b[N+1],ans[N+1],n,m,p,c=0;
int main(){
scanf("%d%d",&n,&m);
rep(i,1,n){
scanf("%d",&p);
for(register int j=0;j<=N;j+=p) b[j]=(p>b[j]?p:b[j]);
}
rep(i,1,N) {while (!b[c]||c+b[c]<=i) c++; g[i]=c;}
rep(i,1,N){
if (g[i]==i) {ans[i]=-1;continue;}
if (ans[g[i]]<0) ans[i]=ans[g[i]]; else ans[i]=ans[g[i]]+1;
}
rep(i,1,m){
scanf("%d",&p);
if (ans[p]<0) printf("oo\n"); else printf("%d\n",ans[p]);
}
}