/* Name:poj 1426 FindTheMultple Author:Unimen Date: 1/05/2011 13:49 Description:广搜 同余定理 */ /* 解题报告: 1、广搜索,同余定理 */ #include <iostream> #include <cstring> #include <queue> using namespace std; int visited[210]; long long anResult; int main() { int n; int next1, next2; long long temp; while(cin>>n && n) { memset(visited, 0, sizeof(visited)); queue<long long> que; visited[1] = 1; que.push(1); while(!visited[0]) { temp = que.front(); que.pop(); next1 = (temp * 10) % n; next2 = (next1 + 1) % n; if(0 == visited[next1]) { visited[next1] = 1; que.push(temp * 10); anResult = temp * 10; } if(0 == visited[next2]) { visited[next2] = 1; que.push(temp * 10 + 1); anResult= temp * 10 + 1; } } cout<<anResult<<endl; } return 0; }