POJ

来源:互联网 发布:python 数据缺失 编辑:程序博客网 时间:2024/06/01 08:33

题意:就是只有1和0组成的一个数,能整除N.

因为答案不唯一,所以可以暴力的用BFS求出来很简单。

#include <iostream>#include <queue>#include <cstdio>using namespace std;typedef  unsigned long long  ull;void bfs(ull n){    queue< ull> q;    q.push(1);    while(!q.empty())    {        ull s = q.front();        q.pop();        if(s % n == 0)        {            cout << s << endl;            return;        }        q.push(s * 10);        q.push(s * 10 +1);    }    return ;}int main(){    ull n;    while(cin >> n && n)    {        bfs(n);    }    return 0;}

0 0
原创粉丝点击