POJ-1426-Find The Multiple

来源:互联网 发布:mac safari缓存文件 编辑:程序博客网 时间:2024/06/08 05:38
Find The Multiple
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 28387 Accepted: 11779 Special Judge

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.

Sample Input

26190

Sample Output

10100100100100100100111111111111111111

Source

Dhaka 2002


题意,输入一个数n,让你找出任意一个由0,1,组成的十进制数是N的倍数;

每次搜索就是搜两种情况

1、a*10

2、a*10+1

//DFS#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;int n,flag;void DFS(unsigned long long a,int step){    if(step == 19 || flag)        return ;    if(a%n == 0)    {        printf("%lld\n",a);        flag = 1;        return ;    }    else    {        DFS(a*10,step+1);        DFS(a*10+1,step+1);    }    return ;}int main(){    while(~scanf("%d",&n) && n)    {        flag = 0;        DFS(1,0);    }    return 0;}//BFS#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#include <queue>#include <cmath>using namespace std;const int MAXN=30+5;typedef  long long ll;void bfs(const ll n){    ll i=1,k;    queue<ll>q;    q.push(i);    while(!q.empty())    {        k=q.front();        q.pop();        if(k%n==0)        {            printf("%lld\n",k);            return ;        }        q.push(k*10);        q.push(k*10+1);    }}int main(){    int n;    while(~scanf("%d",&n)&&n)    {        bfs(n);    }    return 0;}


0 0