用队列会TLE
#include <iostream>
#include <stdio.h>#include <string.h>
using namespace std;
int n;
long long int ans;
long long int num[10000000];
long long int bfs()
{
int top = 0, tail = 0;
num[tail++] = 1;
long long int now,temp;
while(top<tail)
{
now = num[top++];
if(now % n == 0)
return now;
num[tail++]= now*10;
num[tail++] = now * 10 + 1;
}
return 0;
}
int main()
{
while(scanf("%d",&n) != EOF,n)
{
printf("%lld\n",bfs());
}
return 0;
}