1. 程式人生 > 其它 >Find The Multiple POJ - 1426

Find The Multiple POJ - 1426

技術標籤:簡單搜尋

Find The Multiple POJ - 1426

題目

思路:直接bfs搜帶1和0的所有數,直到能被n整除
有點玄學,C++超時,G++卻能AC

程式碼如下

#include<iostream>
#include<queue>

using namespace std;

typedef long long ll;

ll n;

void bfs(){
	
	queue<ll> q;
	q.push(1);
	
	while(q.size()){
		ll t = q.front();
		q.pop();
		
		if
(t % n == 0){ cout << t << endl; return; } ll x = t*10; //搜尋t*10 ll y = x+1; //搜尋t*10+1 q.push(x); q.push(y); } } int main(){ while(cin>>n, n){ bfs(); } return 0; }