# Self-Numbers解题报告

100 10
1 2 3 4 5 6 7 11 12 13

13
1 3 5 7 9 20 31 75 86 97

1<=N<=10^7，1<=K<=5000

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<ctime>
#include<cctype>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<vector>
using namespace std;
int s[5005],n,k,num,a[10000005];
inline void scan(int &v)//读入优化
{
v=0;char c=0;int p=1;
while(c<'0'||c>'9'){if(c=='-')p=-1;c=getchar();}
while(c>='0'&& c<='9'){v=(v<<3)+(v<<1)+c-'0';c=getchar();}
v*=p;
}
int d(int x)
{
int ans=x;
while(x)
ans+=x%10,x/=10;
return ans;
}
bool check(int x)//检测是否是Self-Number
{
bool flag=true;
for(int i=x>54?x-54:0;i<=x;i++)
if(d(i)==x)flag=false;
return flag;
}
int main()
{
//freopen("test.in","r",stdin);
//freopen("test.out","w",stdout);
scanf("%d%d",&n,&k);
for(int i=1;i<=k;i++)scan(s[i]);
for(int i=1;i<=n;i++)
if(check(i))
num++,a[num]=i;
cout<<num<<endl;
for(int i=1;i<=k;i++)
printf("%d ",a[s[i]]);
return 0;
}

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<ctime>
#include<cctype>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<vector>
using namespace std;
int s[5005],n,k,num,a[10000005];
bool flag[10000005];
inline void scan(int &v)//读入优化
{
v=0;char c=0;int p=1;
while(c<'0'||c>'9'){if(c=='-')p=-1;c=getchar();}
while(c>='0'&& c<='9'){v=(v<<3)+(v<<1)+c-'0';c=getchar();}
v*=p;
}
void d(int x)
{
int ans=x;
while(x)
ans+=x%10,x/=10;
flag[ans]=true;
}
int main()
{
//freopen("test.in","r",stdin);
//freopen("test.out","w",stdout);
scanf("%d%d",&n,&k);
for(int i=1;i<=k;i++)scan(s[i]);
for(int i=1;i<=n;i++)
{
if(!flag[i])//没被筛
num++,a[num]=i;
d(i);//筛
}
cout<<num<<endl;
for(int i=1;i<=k;i++)
printf("%d ",a[s[i]]);
return 0;
}