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. 自定义Spring Shell

    目录 概述 自定义内置命令 禁用内置命令 覆盖内置命令 自定义命令提示符 自定义命令行选项行为 自定义参数转换器 概述 官网:https://projects.spring.io/spring-she ...

  2. Android sdk 更新失败解决方发整理

    解决办法: 设置本地hosts windows里hosts位置在C:\Windows\System32\drivers\etc,找到hosts文件 直接在hosts文件的最后加一行: 74.125.2 ...

  3. 事件驱动模型实例详解(Java篇)

    或许每个软件从业者都有从学习控制台应用程序到学习可视化编程的转变过程,控制台应用程序的优点在于可以方便的练习某个语言的语法和开发习惯(如.net和java),而可视化编程的学习又可以非常方便开发出各类 ...

  4. MVC进阶学习--View和Controller之间的数据传递(二)

    1. 使用Request.Form MVC 将页面简单化,与WebForm中的事件机制完全不同,就和普通的html标签表单提交没有任何区别(当然WebForm中的事件机制其实也是表单提交).在表单提交 ...

  5. Android控件ListView获取item中EditText值

    能够明白,如今没有直接方法能够获得ListView中每一行EditText的值. 解决方式:重写BaseAdapter,然后自行获取ListView中每行输入的EditText值. 大概算法:重写Ba ...

  6. web开发之html5---html5 动画特效舞动的雨伞

    http://www.cnblogs.com/stoneniqiu/p/4199294.html

  7. ASP.NET动态网站制作(19)-- C#(2)

    前言:C#的第二次课,依旧讲解C#的基础知识. 内容: 1.GC:垃圾回收机制,可以回收托管模块中的垃圾. 2.值类型和引用类型:  (1)值类型:所有的数值类型都是值类型,如int,byte,sho ...

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

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

  9. Brain Network (easy)(并查集水题)

    G - Brain Network (easy) Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & ...

  10. 在fc6上搭tftpd

    公司的开发环境依然停留在fc6上,,,,对..很旧,旧到想死. 我在没有进一步熟悉ubuntu的基础上,为了保持ABI一致. 只能依旧在FC6 上开发. 可是现在发现开发完成,我要在fc6上文件到wi ...