#include <iostream>
#include <queue>
using namespace std;
int n;
void bfs()
{
queue<long long> q;
q.push(1);
while(q.size())
{
long long p=q.front();
q.pop();
if(p%n==0)
{
cout<<p<<"\n";
return;
}
q.push(p*10);
q.push(p*10+1);
}
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
while(cin>>n&&n)
bfs();
}
Find The Multiple POJ - 1426 (BFS)
原文:https://www.cnblogs.com/baccano-acmer/p/10104281.html