bfs。
#include<iostream>
#include<queue>
using namespace std;
int n;
void bfs()
{
queue<long long> q;
q.push(1);
long long u;
while(q.size())
{
u = q.front();
q.pop();
if(u % n == 0)
{
cout << u << endl;
return;
}
q.push(10 * u);
q.push(10 * u + 1);
}
}
int main()
{
while(cin >> n && n)
bfs();
// system("pause");
return 0;
}