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

  1. 2
  2. 6
  3. 19
  4. 0

Sample Output

  1. 10
  2. 100100100100100100
  3. 111111111111111111

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

  1. 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. 不需要Root即可Hook别人APP的方法

    *:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } ...

  2. codeforces 427 div.2 F. Roads in the Kingdom

    F. Roads in the Kingdom time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  3. Downloading jQuery

    Compressed and uncompressed copies of jQuery files are available. The uncompressed file is best used ...

  4. staitic_cast原理与使用

    本文以下述结构为例: 总结如下: 1) static_cast用于有直接或间接关系的指针或引用之间 转换.没有继承关系的指针不能用此转换,即使二者位于同一类体系中.比如,Left,Right之间不能用 ...

  5. 快速清除MS SQL SERVER 日志

    USE [master] GO ALTER DATABASE yourdatabase SET RECOVERY SIMPLE WITH NO_WAIT GO ALTER DATABASE yourd ...

  6. Oracle关于快速缓存区应用原理

    为什么oracle可以对于大量数据进行訪问时候能彰显出更加出色表现,就是通过所谓的快速缓存来实现数据的快速运算与操作.在之前的博文中我已经说过sql的运行原理,当我们訪问数据库的数据时候,首先不是从数 ...

  7. 基于Linux整形时间的常用计算思路

    上一次分享了Linux时间时区详解与常用时间函数,相信大家对Linux常见时间函数的使用也有了一定的了解,在工作中遇到类似获取时间等需求的时候也一定能很好的处理.本文基于Linux整形时间给出一些简化 ...

  8. Unity框架入门

    介绍Unity框架之前,先要说几个概念DIP依赖倒置原则.IOC控制反转.DI依赖注入 DIP是设计原则之一,定义:上层不应该依赖于底层,两者都依赖于抽象: 抽象不依赖于细节,细节应该依赖于抽象. 像 ...

  9. java拾遗3----XML解析(三) StAX PULL解析

    使用PULL方式解析XML: Pull是STAX的一个实现 StAX是The Streaming API for XML的缩写,一种利用拉模式解析(pull-parsing)XML文档的API StA ...

  10. 为什么不写 @RequestParam 也能拿到参数?

    三种写法,test(String name), test(@RequestParam String name), test(@RequestParam("userName") St ...