一道BFS题。要从数据的构成考虑
#include <cstdio>
#include <iostream>
#include <queue>
using namespace std;
typedef long long LL;
void bfs(int n){
queue<LL> q;
q.push(1);
while(!q.empty()){
if(q.front()%n==0){printf("%lld\n",q.front());return;}
LL top = q.front();
q.pop();
q.push(top*10);
q.push(top*10+1);
}
}
int main(){
int n;
while(~scanf("%d",&n)&&n){
bfs(n);
}
}