E - Find The Multiple(搜索极为巧妙的应用)

#include<iostream>
#include<queue>

using namespace std;

typedef long long ll;

int n;

void bfs(ll x){
  queue<ll> q;
  q.push(x);

  while( !q.empty() ){
    ll t = q.front(); q.pop();

    if(t % n == 0){
      cout << t << endl;
      return;
    }

    q.push(t*10);
    q.push(t*10 + 1);
  }

}

int main(){
  ios::sync_with_stdio(false);

  while(cin >> n){
    if(n == 0)
      break;

    bfs(1);

  }

  return 0;
}

 

posted @ 2019-07-30 18:42  zuo_ti_jia  阅读(159)  评论(0编辑  收藏  举报