POJ1426 Find The Multiple DFS

来源:互联网 发布:sql编程基础 编辑:程序博客网 时间:2024/06/17 05:36

题解:

题目给你一个n,然后让你用0和1组成的十进制数如果能满足这个数%n==0就可以输出,因为n最多有到200,所以一开始并不知道是不是要大数了…后来发现用unsigned long long 就可以,具体的看代码吧

代码

#include <cstdio>#include <queue>#include <cstring>#include <iostream>#include <cstdlib>#include <algorithm>#include <vector>#include <map>#include <string>#include <set>#include <ctime>#include <cmath>#include <cctype>using namespace std;#define MAX 100000#define LL long longint cas=1,T;int flag = 0;void dfs(unsigned long long t,int n,int step){    if (flag)        return;    if (t%n==0)    {        printf("%llu\n",t);        flag=1;        return;    }    if (step==19)               //再搜索下去就要溢出了        return;    dfs(t*10,n,step+1);    dfs(t*10+1,n,step+1);}int main(){    int n;    while (scanf("%d",&n) && n)    {       flag=0;       dfs(1,n,0);    }    //freopen("in","r",stdin);    //scanf("%d",&T);    //printf("time=%.3lf",(double)clock()/CLOCKS_PER_SEC);    return 0;}

题目

Find The Multiple

Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u

POJ 1426

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

2
6
19
0

Sample Output

10
100100100100100100
111111111111111111

0 0