参考:http://www.cnblogs.com/ACShiryu/archive/2011/07/24/2115356.html
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <queue> 5 using namespace std; 6 int main() 7 { 8 int n; 9 while (cin>>n,n) 10 { 11 queue<long long> q; 12 q.push(1); 13 while (!q.empty()) 14 { 15 long long temp=q.front(); 16 q.pop(); 17 if (temp%n==0) 18 { 19 cout<<temp<<endl; 20 break; 21 } 22 q.push(temp*10); 23 q.push(temp*10+1); 24 } 25 } 26 27 return 0; 28 }