poj 1426 Find The Multiple 搜索进阶-暑假集训

E - Find The Multiple

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

Submit Status

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

#include<iostream>
#include<algorithm>
#include<stdio.h>
using namespace std;

int n, flag;void DFS(unsigned long long result, int n, int digit);//result是我们最后要求的结果是n的倍数,n是读入的数据,digit是result的位数;unsigned long long result=1844674473709551616LL,其实就是一个大数,因为本题说只要任意一组数据就行,所以要对数的大小进行一个限制。此程序限制就是19位,

int main()
{
while(cin >> n, n)
{
flag=0;
DFS(1, n, 0);//因为任何一个由0和1构成的数据开头都为1,且位数是从零开始的;
}
return 0;
}
void DFS(unsigned long long result, int n, int digit)
{
if(flag==1)return;//这是代表着找到第一个由0和1构成的是n的倍数的result,是为了防止无限递归,因为有很多result;
if(result%n==0)
{
flag=1;
printf("%I64u\n", result);
return;
}
if(digit==19)//因为unsigned long long 是19位
return;
//搜索的两个方向,result的后一位可能是0也可能是1
DFS(result*10, n, digit+1);//后一位是0
DFS(result*10+1, n, digit+1);//后一位是1
}

时间: 2024-11-10 18:03:12

poj 1426 Find The Multiple 搜索进阶-暑假集训的相关文章

POJ 1426 &lt;Find The Multiple&gt; &lt;搜索&gt;

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 mo

poj 3278 Catch That Cow-搜索进阶-暑假集训

Catch That Cow Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Description Farmer John has been informed of the location of a fugitive cow and wants to catch her immediately. He starts at a point N (0 ≤ N ≤

[题解] [BFS] POJ 1426 - Find The Multiple

p { margin-bottom: 0.25cm; line-height: 115% } a:link { } VJudge题目:https://cn.vjudge.net/contest/279018#problem/L 即POJ 1426 - Find The Multiple:http://poj.org/problem?id=1426 题目要求: 给出一个不大于200的整数n,要求找到任意一个n的倍数(十进制),并且这个倍数只由1与0组成,最多100位. 输入输出:输入以0结束. 示

POJ 1426 Find The Multiple(寻找倍数)

p.MsoNormal { margin-bottom: 10.0000pt; font-family: Tahoma; font-size: 11.0000pt } h1 { margin-top: 5.0000pt; margin-bottom: 5.0000pt; text-align: left; font-family: 宋体; font-weight: bold; font-size: 24.0000pt } span.10 { font-family: "Times New Rom

广搜+打表 POJ 1426 Find The Multiple

POJ 1426   Find The Multiple Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 25734   Accepted: 10613   Special Judge Description Given a positive integer n, write a program to find out a nonzero multiple m of n whose decimal representati

DFS/BFS(同余模) POJ 1426 Find The Multiple

题目传送门 1 /* 2 题意:找出一个0和1组成的数字能整除n 3 DFS:200的范围内不会爆long long,DFS水过~ 4 */ 5 /************************************************ 6 Author :Running_Time 7 Created Time :2015-8-2 14:21:51 8 File Name :POJ_1426.cpp 9 ******************************************

20200202 POJ - 3126 Prime Path POJ - 1426 Find The Multiple

>>>>>>>>>POJ 1426直达?? >>>>>>>>>POJ 3126直达?? 做了这么几道搜索题,感觉差不多也摸出了门路,模板差不多记下来了,只是面对不同的题目算法不同罢了 简单写一下想法,搞明白搜索的主题到底是什么(之前的mutiple那题,一开始就没想明白到底搜谁,就没想到算法 TBC(晚上再写 ===================================分割线=======

poj 1426 Find The Multiple (bfs 搜索)

Find The Multiple Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 18012   Accepted: 7297   Special Judge Description Given a positive integer n, write a program to find out a nonzero multiple m of n whose decimal representation contains

[深度优先搜索] POJ 1426 Find The Multiple

Find The Multiple Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 28550   Accepted: 11828   Special Judge Description Given a positive integer n, write a program to find out a nonzero multiple m of n whose decimal representation contains