# 3.1.3 Humble Numbers 丑数

3.1.3 Humble Numbers 丑数

``````4 19
2 3 5 7``````

``````27
``````

``````
#include<stdio.h>
#include<algorithm>
#include<memory.h>
using namespace std;
#define INF 2147483647
int N,K;
int num[101],humb[100001]={1,1},point[101];
int min(){
int i,min=INF;
for(i=0;i<N;i++)
if(num[i]*humb[point[i]]<min) min=num[i]*humb[point[i]];
for(i=0;i<N;i++)
if(num[i]*humb[point[i]]==min) point[i]++;
return min;
}
int main(){
int i;
while(scanf("%d%d",&N,&K)!=EOF){
memset(point,0,sizeof(point));
for(i=0;i<N;i++)
scanf("%d",&num[i]);
sort(num,num+N);
for(i=1;i<=K;i++){
humb[i]=min();
}
printf("%d\n",humb[K]);
}
return 0;
}``````

``````#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cctype>
#include<vector>
#include<algorithm>
#include<cstring>
#define oo 2000000000
using namespace std;
int n,m;
int a[100005],w[105];
long long ans[100005];

int main()
{
scanf("%d%d",&m,&n);
for(int i=1;i<=m;i++)
{
scanf("%d",&a[i]);
w[i]=1;
}

ans[1]=1;
for(int i=2;i<=n+1;i++)
{
ans[i]=oo;
for(int j=1;j<=m;j++)
{
while(a[j]*ans[w[j]]<=ans[i-1]) w[j]++;;
if(a[j]*ans[w[j]]<ans[i]) ans[i]=a[j]*ans[w[j]];
}
}
cout<<ans[n+1];
return 0;
}
``````