E - Find The Multiple (POJ - 1426)
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int N = 15+5;
int n;
void bfs() {
queue<ll> q;
q.push(1);
while(!q.empty()) {
ll t = q.front();
q.pop();
if(t%n==0) {
printf("%lld\n", t);
return ;
}
q.push(t*10);
q.push(t*10+1);
}
}
int main(void) {
while(scanf("%d", &n)==1 && n) {
bfs();
}
return 0;
}