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 (0) 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

大致题意:

给个n,找n的十进制倍数,仅有 0 和 1 组成,找一个就行,随便哪一个。

解题思路:

观察以下0,1串: 

  1 

  10 11

  100 101 110 111

  从n=1开始, 重复 n*10 与 n*10+1 ,由此遍历所有01串。

  BFS,DFS皆可,以下采用DFS。

 #include <iostream>
#include <queue>
#include <cstdio>
using namespace std;
queue<unsigned long long> s;
int n;//输入
unsigned long long temp,p;
void bfs()
{
while(!s.empty())
s.pop();
temp=;
s.push(temp);
while(!s.empty())
{
p=s.front();
s.pop();
if(p%n==)
{
printf("%lld\n",p);//lld!
break;
}
s.push(p*);
s.push(p*+);
}
}
int main(){
while(scanf("%d",&n),n)
{
bfs();
}
return ;
}

ZOJ 1530 - Find The Multiple的更多相关文章

  1. POJ题目细究

    acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP:  1011   NTA                 简单题  1013   Great Equipment     简单题  102 ...

  2. 【转】POJ百道水题列表

    以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...

  3. ZOJ 1136 Multiple (BFS)

    Multiple Time Limit: 10 Seconds      Memory Limit: 32768 KB a program that, given a natural number N ...

  4. ZOJ People Counting

    第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ  3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...

  5. ZOJ 3686 A Simple Tree Problem

    A Simple Tree Problem Time Limit: 3 Seconds      Memory Limit: 65536 KB Given a rooted tree, each no ...

  6. ZOJ 3494 BCD Code(AC自动机+数位DP)

    BCD Code Time Limit: 5 Seconds      Memory Limit: 65536 KB Binary-coded decimal (BCD) is an encoding ...

  7. zoj 3469 Food Delivery 区间dp + 提前计算费用

    Time Limit: 2 Seconds      Memory Limit: 65536 KB When we are focusing on solving problems, we usual ...

  8. zoj 3795 Grouping tarjan缩点 + DGA上的最长路

    Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Submit Status Practic ...

  9. ZOJ 3430 Detect the Virus

    传送门: Detect the Virus                                                                                ...

随机推荐

  1. Identity 验证,Authorize 特性

    多类型角色访问 //[Authorize] //[Authorize(Roles = "User")] //[Authorize(Roles="Administrator ...

  2. Android集成科大讯飞SDK语音听写及语音合成功能实现

    前言 现在软件设计越来越人性化.智能化.一些常见的输入都慢慢向语音听写方向发展,一些常见的消息提示都向语音播报发展.所以语音合成和语音听写是手机软件开发必不可少的功能.目前国内这方面做的比较好的应该是 ...

  3. Json.Net序列化和反序列化设置

    首先补充一点,Json.Net是支持序列化和反序列化DataTable,DataSet,Entity Framework和NHibernate的.我举例说明DataTable的序列化和反序列化.创建一 ...

  4. iOS 获取系统目录

    //获取根目录 NSString *homePath = NSHomeDirectory(); NSLog(@"Home目录:%@",homePath); //获取Document ...

  5. 在Vim中查看文件编码

    :set fileencoding 即可显示文件编码格式. 如果你只是想查看其它编码格式的文件或者想解决 用Vim查看文件乱码的问题,那么在 ~/.vimrc 文件中添加以下内容: set encod ...

  6. php基础之 ->, =>,@,&,::,%符号

    => 是数组成员访问符号 -> 是对象成员访问符号 比如: $array = array("site map"=>"map.php"); // ...

  7. 利用html5中的localStorage获取网页被访问的次数

    利用html5中的localStorage获取网页被访问的次数 <!DOCTYPE html> <html> <head> <meta charset=&qu ...

  8. Raknet实现的简单服务器与客户端的交互

    1. 首先下载Raknet的源代码,我用的是4.0的,不是最新的,解压后编译DLL工程,编译完成后进入解压的根目录下,进入Lib文件夹下找到RakNet_DLL_Debug_Win32.dll,  R ...

  9. 寻找最大数--nyoj题目448

    寻找最大数 时间限制:1000 ms  |  内存限制:65535 KB 难度:2   描述 请在整数 n 中删除m个数字, 使得余下的数字按原次序组成的新数最大, 比如当n=920813467185 ...

  10. MYSQL select ....outfile.....from.....

    select .... outfile  'file_path' fields terminate by '\t' lines terminate by '\r\n' from table_name; ...