POJ1426——DFS——Find The Multiple

http://poj.org/problem?id=1426

/*
暴力发现最大数目不超过19位,开unsigned long long 水过
*/
/************************************************
* Author        :Powatr
* Created Time  :2015-8-9 15:30:37
* File Name     :E.cpp
 ************************************************/

#include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std;

#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int MAXN = 1e5 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
int n;
queue <unsigned long long > q;
unsigned long long  bfs(){
    while(!q.empty()) q.pop();
    q.push(1);
    while(!q.empty()){
        unsigned long long x = q.front();
        q.pop();
        if(x % n == 0)  return x;
        q.push(x*10);
        q.push(x*10 + 1);
    }
}
int main(){
    while(~scanf("%d", &n) && n){
        printf("%llu\n", bfs());
    }
    return 0;
}
            

  

posted @ 2015-08-09 16:07  Painting、时光  阅读(132)  评论(0编辑  收藏  举报