灰常水的搜索。 == 因为数据太弱unsigned int64足够存的下答案。。从1dfs下去就行了
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <stdio.h>
#include <string.h>
using namespace std;
bool OK;
typedef unsigned __int64 ll;
ll n;
void dfs( ll now, int k)
{
//cout << " now : " << now << endl;
if( OK )
return;
if( now % n == 0 )
{
cout << now << endl;
OK = 1;
return;
}
if( k == 19 )
return;
dfs( now * 10 + 1, k + 1 );
dfs( now * 10, k + 1 );
}
int main()
{
while( cin >> n && n)
{
OK = 0;
dfs( 1, 0 );
}
return 0;
}