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. latex 固定图片位置

    1,插入并列的子图 \usepackage{subfigure} \begin{figure}[H] \centering \subfigure[SubfigureCaption]{ \label{F ...

  2. iOS 获取系统目录

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

  3. <转>让SVN用户能够修改自身密码的PHP页面

    1.修改Apache配置文件因为我在安装和配置SVN的时候,对Apache的配置文件进行过优化,将所有关于SVN的配置都写在了/opt/apache2/conf/extra/httpd-svn.con ...

  4. B - A + B Again

    Description There must be many A + B problems in our HDOJ , now a new one is coming.         Give yo ...

  5. golang make the first character in a string lowercase/uppercase

    import ( "unicode" ) func UcFirst(str string) string { for i, v := range str { return stri ...

  6. QString转LPCWSTR

    QFileInfo info("./records.db"); std::string str = info.absoluteFilePath().toStdString(); / ...

  7. GDAL与OpenCV2.X数据转换(适合多光谱和高光谱等多通道的遥感影像)

    一.前言 GDAL具有强大的图像读写功能,但是对常用图像处理算法的集成较少,OpenCV恰恰具有较强的图像处理能力,因此有效的结合两者对图像(遥感影像)的处理带来了极大的方便.那么如何实现GDAL与o ...

  8. NFC-P2P MODE

    今日看见有关国内电信业者要合组TSM (Trusted Service Manager)提供NFC 服务的新闻, 这是属于NFC 所能提供的3种Mode中的Card emulation mode (就 ...

  9. SpringBoot优化内嵌的Tomcat

    SpringBoot测试版本 <parent> <groupId>org.springframework.boot</groupId> <artifactId ...

  10. poj 2975 Nim_最经典的Nim取石子

    题意:给你n堆石头,每次只能在一堆取最少一个石子,最后拿走最后一堆的为胜者,问胜者有多少种赢得取法 #include <iostream> #include<cstdio> u ...