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;
}