[kuangbin带你飞]专题一 简单搜索 E

来源:互联网 发布:梯形螺纹加工编程 编辑:程序博客网 时间:2024/06/06 03:16

E - Find The Multiple

 POJ - 1426   

Description

a positive integer n, write a program to find out a nonzero multiple m of n whose decimal representation contains only the digits 0 and 1. You may assume that n is not greater than 200 and there is a corresponding m containing no more than 100 decimal digits.

Input

The input file may contain multiple test cases. Each line contains a value of n (1 <= n <= 200). A line containing a zero terminates the input.

Output

For each value of n in the input print a line containing the corresponding value of m. The decimal representation of m must not contain more than 100 digits. If there are multiple soluhem is acceptable.

Sample Input

26190

Sample Output

1010010010010010010011111111111111111

题意:找到一个数是n的倍数,且只能有0,1构成。本来还在想100超过long long 怎么搞。事实上不用想那么多 直接BFS就能过。DFS的话是到20层(long long 范围)。

ACcode:

#include <iostream>#include <cstdio>#include <queue>using namespace std;int n;long long bfs(){    queue<long long> q;    q.push(1);    while(!q.empty())    {       long long p=q.front();      q.pop();            q.push(p*10);            if((p*10)%n==0) return (p*10);            q.push(p*10+1);            if((p*10+1)%n==0) return (p*10+1);    }    return 0; //一定要加,不加必WA }int main(){    while(scanf("%d",&n)==1 &&n)    printf("%lld\n",bfs());    return 0;}

阅读全文
0 0
原创粉丝点击