# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
134509 | degelo | Brunhilda’s Birthday (BOI13_brunhilda) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#define inf 1000000000
#define maxn 20000
using namespace std;
long long int prod=1;
int m,q;
int p[maxn];
int dp[maxn];
int DP(int k){
if(dp[k]!=0) return dp[k];
if(k==0) return 0;
if(k<p[m-1]) return 1;
int resp=inf;
for(int i=0;i<m;i++){
if(k%p[i]==0) continue;
resp=min(resp,DP((k/p[i])*p[i])+1);
}
return resp;
}
int main(){
scanf("%d %d",&m,&q);
for(int i=0;i<m;i++){
scanf("%d",&p[i]);
}
for(int i=0;i<m;i++){
prod*=p[i];
if(prod>maxn) break;
}
for(int i=0;i<q;i++){
int n;
scanf("%d",&n);
if(n>=prod) printf("oo\n");
else printf("%d\n",DP(n));
}
}
int main(){
scanf("%d %d",&m,&q);
for(int i=0;i<m;i++){
scanf("%d",&p[i]);
}
for(int i=0;i<m;i++){
prod*=p[i];
if(prod>maxn) break;
}
for(int i=0;i<q;i++){
int n;
scanf("%d",&n);
if(n>=prod) printf("oo\n");
else printf("%d\n",DP(n));
}
}