1 #include <iostream> 2 #include <cstdio> 3 #include <algorithm> 4 using namespace std; 5 typedef long long ll; 6 int n; 7 bool flag = false; 8 void dfs(ll num, int len){ 9 if(len > 19 || flag == 1){ 10 return; 11 } 12 if(num % n == 0){ 13 flag = true; 14 cout << num << endl; 15 return; 16 } 17 dfs(num * 10, len + 1); 18 dfs(num * 10 + 1, len + 1); 19 } 20 int main(){ 21 while(scanf("%d", &n)){ 22 if(n == 0) 23 break; 24 flag = false; 25 dfs(1, 1); 26 } 27 28 return 0; 29 }
原文:https://www.cnblogs.com/pureayu/p/13681784.html