Find The Multiple(POJ--1426

来源:互联网 发布:假钞在淘宝中的暗语 编辑:程序博客网 时间:2024/06/05 15:08

Description

Given 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 solutions for a given value of n, any one of them is acceptable.
题意:多组输入,每组输入一个n,求能整除n且只能由0和1组成的数,如果有多种情况只要输出一种即可。

Sample Input

26190

Sample Output

10100100100100100100111111111111111111

#include <cstdio>#include <iostream>#include <cstring>#include <algorithm>#include <cmath>#include <queue>#define MAX 100005#define mod 99991using namespace std;int n;void BFS(){    queue <long long>q;             //求得的数可能超过整型,所以用long long型的队列    q.push(1);                               //求得的数的最高位肯定是1而不会是0    while(!q.empty())    {        long long int x;        x=q.front();        q.pop();        if(x%n==0)        {          printf("%lld\n",x);          return ;        }        q.push(x*10);                  //要么添0        q.push(x*10+1);              //要么添1    }}int main(){    //freopen("lalala.text","r",stdin);    while(~scanf("%d",&n))    {        if(!n)            break;        BFS();    }    return 0;}<strong></strong>


0 0
原创粉丝点击