Find the Multiply (BFS)
#include<bits/stdc++.h>
using namespace std;
void BFS(int n){
queue<long long> q;
q.push(1);
while(!q.empty()){
long long current=q.front();
q.pop();
if(current%n==0){
cout<<current<<endl;
break;
}
q.push(10*current);
q.push(10*current+1);
}
return ;
}
int main(){
int n;
while(cin>>n){
if(n==0){
break;
}
BFS(n);
}
return 0;
}
using namespace std;
void BFS(int n){
queue<long long> q;
q.push(1);
while(!q.empty()){
long long current=q.front();
q.pop();
if(current%n==0){
cout<<current<<endl;
break;
}
q.push(10*current);
q.push(10*current+1);
}
return ;
}
int main(){
int n;
while(cin>>n){
if(n==0){
break;
}
BFS(n);
}
return 0;
}