題目:
給定一個正整數n,請編寫一個程序來尋找n的一個非零的倍數m,這個m應當在十進制表示時每一位上只包含0或者1。你可以假定n不大於200且m不多於100位。
提示:本題采用Special Judge,你無需輸出所有符合條件的m,你只需要輸出任一符合條件的m即可。
輸入:
輸入包含多組數據,每組數據僅一行,只包含一個正整數n (1 <= n <= 200).
輸出:
對於輸入的每組n,都輸出任一符合條件的m。即使有多個符合條件的m,你也只需要輸出一個即可。
樣例:
分析:unsigned long long 暴力DFS就完事了(ノ>ω<)ノ
ac代碼如下
#include<iostream> #include<sstream> #include<cstdio> #include<string> #include<cstring> #include<algorithm> #include<functional> #include<iomanip> #include<numeric> #include<cmath> #include<queue> #include<vector> #include<set> #include<cctype> #define PI acos(-1.0) const int INF = 0x3f3f3f3f; const int NINF = -INF - 1; typedef long long ll; using namespace std; int n; int dfs(unsigned long long x, int t) { if (t > 19) return 0; if (x % n == 0) { cout << x << endl; return 1; } if (dfs(x * 10, t + 1)) return 1; if (dfs(x * 10 + 1, t + 1)) return 1; return 0; } int main() { while (cin >> n) { if (n == 0) break; dfs(1, 0); } return 0; }