题目:

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

题意:

本题要找出数m,m是只有0和1构成的十进制数,并且是n的倍数,若有多个答案,输出任意一个就可以。

题解:

经过思考会发现m最大不会超过unsigned long long 的范围,所以用unsigned long long保存就可以,接下来就是深搜就ok。

代码:

#include <iostream>

using namespace std;
unsigned long long ans;
bool f; void dfs(unsigned long long s,int n,int k)
{
if(f) return ;
if(s%n==) {ans=s;f=true; return ;}
if(k==) return ; //如果k超过19就不在unsigned long long的范围内了
dfs(s*,n,k+);
dfs(s*+,n,k+);
return ;
} int main()
{
int n;
while(cin>>n,n)
{
ans=;
f=false;
dfs(,n,);
cout<<ans<<endl;
}
return ;
}

poj 1426 Find The Multiple (简单搜索dfs)的更多相关文章

  1. POJ - 1426 Find The Multiple(搜索+数论)

    转载自:優YoU  http://user.qzone.qq.com/289065406/blog/1303946967 以下内容属于以上这位dalao http://poj.org/problem? ...

  2. poj 1426 Find The Multiple (bfs 搜索)

    Find The Multiple Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 18012   Accepted: 729 ...

  3. POJ 1426 Find The Multiple --- BFS || DFS

    POJ 1426 Find The Multiple 题意:给定一个整数n,求n的一个倍数,要求这个倍数只含0和1 参考博客:点我 解法一:普通的BFS(用G++能过但C++会超时) 从小到大搜索直至 ...

  4. DFS/BFS(同余模) POJ 1426 Find The Multiple

    题目传送门 /* 题意:找出一个0和1组成的数字能整除n DFS:200的范围内不会爆long long,DFS水过~ */ /************************************ ...

  5. POJ 1426 Find The Multiple(寻找倍数)

    POJ 1426 Find The Multiple(寻找倍数) Time Limit: 1000MS    Memory Limit: 65536K Description - 题目描述 Given ...

  6. 广搜+打表 POJ 1426 Find The Multiple

    POJ 1426   Find The Multiple Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 25734   Ac ...

  7. POJ.1426 Find The Multiple (BFS)

    POJ.1426 Find The Multiple (BFS) 题意分析 给出一个数字n,求出一个由01组成的十进制数,并且是n的倍数. 思路就是从1开始,枚举下一位,因为下一位只能是0或1,故这个 ...

  8. POJ 1426 Find The Multiple (DFS / BFS)

    题目链接:id=1426">Find The Multiple 解析:直接从前往后搜.设当前数为k用long long保存,则下一个数不是k*10就是k*10+1 AC代码: /* D ...

  9. POJ 2243 简单搜索 (DFS BFS A*)

    题目大意:国际象棋给你一个起点和一个终点,按骑士的走法,从起点到终点的最少移动多少次. 求最少明显用bfs,下面给出三种搜索算法程序: // BFS #include<cstdio> #i ...

  10. 简单搜索dfs, 简单的修剪搜索

    选择最合适的语言做一个项目是非常重要的.但,熟练的掌握自己的武器,这也是非常重要的. ========================================================= ...

随机推荐

  1. 初次使用Mybatis

    目录 mybatis简介 导入jar包 创建数据库以及数据库表 创建实体类 创建mapper.xml文件 配置mybatis 测试mybatis 三种查询方式 selectOne selectList ...

  2. jdk 动态代理的原理

    一.代理设计模式 代理设计模式是Java常用的设计模式之一. 特点: 01.委托类和代理类有共同的接口或者父类: 02.代理类负责为委托类处理消息,并将消息转发给委托类: 03.委托类和代理类对象通常 ...

  3. Linux基础操作文件等基础操作

    作业一: 1)  将用户信息数据库文件和组信息数据库文件纵向合并为一个文件/1.txt(覆盖) [root@bogon /]# cd /etc [root@bogon etc]# cat passwd ...

  4. 第二章· Redis管理实战

    数据类型 管理实战 数据类型 String: 字符串类型 Hash: 哈希类型 List: 列表类型 Set: 集合类型 Sorted set: 顺序集合类型 管理实战 通用操作

  5. linux的挂载含义

    Linux下,mount挂载的作用,就是将一个设备(通常是存储设备)挂接到一个已存在的目录上.访问这个目录就是访问该存储设备.linux操作系统将所有的设备都看作文件,它将整个计算机的资源都整合成一个 ...

  6. ASP.NET MVC系列:web.config中ConnectionString aspnet_iis加密与AppSettings独立文件

    1. web.config中ConnectionString aspnet_iis加密 web.config路径:E:\Projects\Libing.Web\web.config <conne ...

  7. 设置QPushbutton按钮背景、鼠标滑过状态、鼠标点击后状态用法

    1.1当要设置QPushbutton按钮背景,字体颜色,鼠标滑过状态,鼠标单击后状态时,可以用QSS来设置,具体的代码如下:     QPushButton *allSelect = new QPus ...

  8. P3389 【模板】高斯消元法

    高斯消元求解n元一次线性方程组的板子题: 先举个栗子: • 2x + y -   z =  8-----------① •-3x - y + 2z = -11---------② •-2x + y + ...

  9. jzoj6101. 【GDOI2019模拟2019.4.2】Path

    题目链接:https://jzoj.net/senior/#main/show/6101 记\(f_i\)为从\(i\)号点走到\(n\)号点所花天数的期望 那么根据\(m\)条边等可能的出现一条和一 ...

  10. vm Linux centos 链接外网

    修改network配置 vi /etc/sysconfig/network-scripts/ifcfg-ens33 修改ONBOOT=yes 重启服务 service network restart ...