一开始用bfs做,但发现用dfs做更快,短小精悍!
#include<cstdio>
#define ll long long
int k;
bool dfs(int cnt,ll sum)
{
if(cnt>18)return false;
if(sum%k==0){
printf("%lld\n",sum);
return true;
}
if(dfs(cnt+1,sum*10))return true;
if(dfs(cnt+1,sum*10+1))return true;
return false;
}
int main()
{
while(~scanf("%d",&k)&&k!=0){
dfs(0,1);
}
return 0;
}