题目传送:Find The Multiple
思路:DFS
AC代码:
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <cctype>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define ULL unsigned long long
#define INF 0x7fffffff
using namespace std;
int dfs(ULL pre, ULL x, ULL n) {
if(pre > x) return 0;//判断是否溢出,溢出了就不是正解
if(x % n == 0) {
cout << x << endl;
return 1;
}
if(dfs(x, x * 10, n)) return 1;
return dfs(x, x * 10 + 1, n);
}
int main() {
int n;
while(scanf("%d", &n) != EOF) {
if(n == 0) break;
dfs(0, 1, n);
}
return 0;
}