poj1426

广搜

View Code
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
using namespace std;

#define maxn 10000000

int n;
long long q[maxn];

long long work()
{
    int front = 0;
    int rear = 0;

    q[rear++] = 1;
    while (1)
    {
        long long temp = q[front++];
        if ((temp * 10) % n == 0)
            return temp * 10;
        if ((temp * 10 + 1) % n == 0)
            return temp * 10 + 1;
        q[rear++] = temp * 10;
        q[rear++] = temp * 10 + 1;
    }
    return -1;
}

int main()
{
//    for (n = 1; n <= 200; n++)
//        printf("%lld\n", work());
    while (scanf("%d", &n), n)
        printf("%lld\n", work());
}

 

posted @ 2013-03-17 19:46  金海峰  阅读(577)  评论(0编辑  收藏  举报