您的位置:首页 > 其它

poj 1426 Find The Multiple

2015-02-02 00:15 447 查看
灰常水的搜索。 == 因为数据太弱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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: