一开始被m的位数吓到了,以为要用高精度 。 后来发现答案不会超long long,也不知道是数据水了还是本来如此。
这样就很简单了, 搜索深度最多19层,每一层只有两个决策: m*10 和m*10+1 。
细节参见代码:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<cmath>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1000000000;
const int maxn = 3000000 + 5;
int n,m,T;
bool dfs(ll v, int d) {
if(v % n == 0) { printf("%I64d\n",v); return true; }
if(d >= 19) return false;
if(dfs(v*10,d+1)) return true;
if(dfs(v*10+1,d+1)) return true;
return false;
}
int main() {
while(~scanf("%d",&n)&&n) {
dfs(1,1);
}
return 0;
}