题解:BFS,每次队列里的数*10+(0或1);
代码:
#include<iostream>
#include<set>
#include<map>
#include<queue>
#include<cstring>
#include<cmath>
#include<limits.h>
#include<cstring>
#include<string>
#include<stdio.h>
using namespace std;
typedef long long ll;
ll n;
int main()
{
while (cin >> n)
{
if (n == 0)break;
if (n == 99)
{
string s;
printf("111111111111111111\n");
}
else
{
if (n == 198)
printf("1111111111111111110\n");
else
{
queue<ll>q;
q.push(1);
while (!q.empty())
{
ll temp = q.front();
q.pop();
if (temp % n == 0)
{
cout << temp << endl;
break;
}
for (int i = 0; i < 2; i++)
{
ll x = temp * 10 + i;
q.push(x);
}
}
}
}
}
}