poj1426

#include<iostream>

#include<cstdio>

using namespace std;

int n;

long long int q[9999999];

void BFS()

{

    int front,rear;

    front=rear=0;

    q[rear]=1;

    rear++;

    long long int top;

    while(rear>front)

    {

        top = q[front];

        if(top%n==0){

            break;

  }

        top *= 10;

        q[rear++]=top;

        q[rear++]=top+1;

        front++;

    }

    printf("%lld\n",top);

}



int main()

{

    while(scanf("%d",&n)&&n){

        BFS();

    }

    return 0;

}

你可能感兴趣的:(poj)