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
}

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

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

    Catch That Cow Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Subm ...

  2. POJ 1426 Find The Multiple --- BFS || DFS

    POJ 1426 Find The Multiple 题意:给定一个整数n,求n的一个倍数,要求这个倍数只含0和1 参考博客:点我 解法一:普通的BFS(用G++能过但C++会超时) 从小到大搜索直至 ...

  3. 广搜+打表 POJ 1426 Find The Multiple

    POJ 1426   Find The Multiple Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 25734   Ac ...

  4. POJ 1426 Find The Multiple(寻找倍数)

    POJ 1426 Find The Multiple(寻找倍数) Time Limit: 1000MS    Memory Limit: 65536K Description - 题目描述 Given ...

  5. POJ.1426 Find The Multiple (BFS)

    POJ.1426 Find The Multiple (BFS) 题意分析 给出一个数字n,求出一个由01组成的十进制数,并且是n的倍数. 思路就是从1开始,枚举下一位,因为下一位只能是0或1,故这个 ...

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

    题目传送门 /* 题意:找出一个0和1组成的数字能整除n DFS:200的范围内不会爆long long,DFS水过~ */ /************************************ ...

  7. POJ 1426 Find The Multiple (DFS / BFS)

    题目链接:id=1426">Find The Multiple 解析:直接从前往后搜.设当前数为k用long long保存,则下一个数不是k*10就是k*10+1 AC代码: /* D ...

  8. POJ - 1426 Find The Multiple(搜索+数论)

    转载自:優YoU  http://user.qzone.qq.com/289065406/blog/1303946967 以下内容属于以上这位dalao http://poj.org/problem? ...

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

    Find The Multiple Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 28550   Accepted: 118 ...

随机推荐

  1. 使用Firebug进行断点调试详解

    利用Firebug我们可以非常方便地对网页上的任何JavaScript代码进行断点调试. 首先,使用快捷键F12在当前页面打开Firebug,并切换到脚本选项卡. 其次,我们需要为指定的js代码添加断 ...

  2. eclipse 开发 scala

    (环境:jdk1.7,scala插件scala-2.1.1.2-site.zip) 1:下载scala插件 http://download.scala-ide.org/sdk/helium/e38/s ...

  3. Maven的配置地址

    http://howtodoinjava.com/tools/eclipse/how-to-import-maven-remote-archetype-catalogs-in-eclipse/ htt ...

  4. php使用imagick模块实现图片缩放、裁剪、压缩示例

    PHP 使用Imagick模块 缩放,裁剪,压缩图片 包括gif图片 缩放 裁剪 复制代码代码如下: /**  * 图片裁剪  * 裁剪规则:  *   1. 高度为空或为零   按宽度缩放 高度自适 ...

  5. 使用Application Loader上传APP流程解读[APP公布]

    本文仅仅是提供一个公布流程的总体思路.假设没有公布经验.建议阅读苹果官方公布文档或者Google搜索具体教程. 1.申请开发人员账号:99美金的(须要信用卡支付),详细流程网上有非常多样例.自行搜索. ...

  6. 【Navicat Premium】之连接Oracle数据库

    1.首先,在连接之前,需要下载oracle官网提供的instantclient-basic-win32-11.2.0.1.0.zip包 官网:http://www.oracle.com/technet ...

  7. linux 时间与本地时间不对应解决办法

    date -s '2015-01-22 13:00:22' #设置时间 clock -w #写入mac操作系统中 -------------------------------------date - ...

  8. Wireshark 与 Tcpdump

    [1]Wireshark 与 Tcpdump Wireshark是Windows下非常容易上手的抓包工具.但在Linux下很难找到一个好用的图形界面抓包工具.还好有Tcpdump.我们可以用Tcpdu ...

  9. 基于HttpClient实现网络爬虫~以百度新闻为例

    转载请注明出处:http://blog.csdn.net/xiaojimanman/article/details/40891791 基于HttpClient4.5实现网络爬虫请訪问这里:http:/ ...

  10. iOS中 HTTP/Socket/TCP/IP通信协议具体解释 韩俊强的博客

    简介: // OSI(开放式系统互联), 由ISO(国际化标准组织)制定 // 1. 应用层 // 2. 表示层 // 3. 会话层 // 4. 传输层 // 5. 网络层 // 6. 数据链接层 / ...