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. 用MVC4+EF改写XXX系统的计划--前言

    感觉自己工作了三年,重来没有自己一个人写一个项目,从开始的策划,功能需求,业务逻辑,扩展,性能优化等等方面去做,从今天起准备发比半年时间重写XXX项目,每天中午和晚上分别花半个小时和一个小时开发,周末 ...

  2. 笔记本开通手机WiFI热点

    启用虚拟wifi: netsh wlan set hostednetwork mode=allow ssid=liuyuduen key=liuyuduen 关闭虚拟Wifi: netsh wlan ...

  3. React-Native个人信息界面

    最近在做一个小练习项目,用户登陆后需要跳转到用户登录信息界面,加班半个小时终于将界面的布局搞定.接触Rect-Native也有一段时间了,以前没有做过ios,只做过android,就布局和开发效率上来 ...

  4. OCMOCM

    14年,OCM考试费12000 15年,考试费19800 对于我来说,1,2年之后是否换工作还是个未知数 在本单位考这个貌似没什么用处,工资也不会突然就涨很多 跳槽的话,专门做数据库感觉压力还挺大 年 ...

  5. Populating Next Right Pointers in Each Node,Populating Next Right Pointers in Each Node II

    Populating Next Right Pointers in Each Node Total Accepted: 72323 Total Submissions: 199207 Difficul ...

  6. 【转】关于C++程序的编码问题

    引用自:http://blog.chinaunix.net/uid-26790551-id-3190813.html 我们传统的程序基本都只在Windows或只在Linux下运行,Windows程序使 ...

  7. SecureCRT使用的技巧 键盘修改

    secureCRT 修改PageUP,PageDown,Home,End键小trick:http://blog.csdn.net/shark_sq/article/details/6722512 所有 ...

  8. Fragment 之 PagerAdapter

    package com.edaixi.main.adapter; import android.content.Context; import android.support.v4.view.Page ...

  9. php 支持递归函数.递归函数就是调用函数本身.

    例子 将一个字符进行颠倒 function reverse_r($str){ if(strlen($str)){ reverse_r(substr($str,1));// } echo substr( ...

  10. Python的tkinter和tkinter.messagebox应用-鼠标和键盘命令绑定

    __author__ = 'Administrator' from tkinter import * import tkinter.messagebox class MainWindow: def b ...