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 题意 : 对于给定的一个数 , 输出的一个数是他的倍数,并且十进制位只有 0 和 1 思路 : DFS 和 BFS 都可以做
  bfs 的代码
#define ll unsigned long long

int n;
void bfs(){
queue<ll>que;
que.push(1); while(!que.empty()){
ll a = que.front();
que.pop(); if (a % n == 0) {
printf("%lld\n", a);
break;
}
que.push(a*10);
que.push(a*10+1);
}
} int main() { while(~scanf("%d", &n) && n){
bfs();
}
//for(int i = 1; i <= 200; i++){
//n = i;
//bfs();
//}
return 0;
}

  而用dfs 做 , 考虑好递归结束的条件,如果这题用 long long 的话就直接 wa 了,有些时候要想想 unsigned 的强大地方可以对长整型变量的精度增加一位。

dfs 的代码 :

  

#define ll unsigned long long
ll n;
int sign; void dfs(ll num, int cnt){
if (cnt > 19 || sign) return;
if (num % n == 0) {
printf("%lld\n", num);
sign = 1;
return; // 递归函数里要写 return , 不能写 break
}
dfs(num*10, cnt+1);
dfs(num*10+1, cnt+1);
} int main() { while(~scanf("%lld", &n) && n){
sign = 0;
dfs(1, 1);
}
return 0;
}

dfs - 卡一个无符号长整形的更多相关文章

  1. The Super Powers UVA 11752 分析分析 求无符号长整形以内的数满足至少可以用两种不同的次方来表示。比如64 = 2^6 = 8^2; 一个数的1次方不算数。

    /** 题目:The Super Powers UVA 11752 链接:https://vjudge.net/contest/154246#problem/Y 题意:求无符号长整形以内的数满足至少可 ...

  2. strtoul (将字符串转换成无符号长整型数)

    strtoul strtoul (将字符串转换成无符号长整型数) 相关函数 atof,atoi,atol,strtod,strtol 表头文件 #include<stdlib.h> 定义函 ...

  3. java 无符号byte转换

    java中的byte类型是有符号的,值得范围是-128-127 做网络通讯时,接收过来的数据往往都是无符号的byte,值得范围是0-255 因此直接转换时,存储到java显示的值就会有问题 int o ...

  4. C语言警告:warning C4018: “<”: 有符号/无符号不匹配

    问题如下: 代码出问题之处:   原因分析: strlen返回一个无符号整型,也就是unsigned型,比较时应该两边的数据类型相同,故严格上来说,应该将m定义为unsigned型.       修改 ...

  5. Java 与无符号那些事儿

    最近在使用 Java 作为 WebSocket 客户端连接 Node.js 的 WebSocket 服务器的时候,由于使用的客户端库比较老,所以遇到了字节符号的问题,上网查了一下,看到这篇文章写的很有 ...

  6. c#中将IP地址转换成无符号整形数的方法与逆变换方法

    我们知道 IP地址就是给每个连接在Internet上的主机分配的一个32bit地址. 按照TCP/IP协议规定,IP地址用二进制来表示,每个IP地址长32bit,比特换算成字节,就是4个字节.而c#中 ...

  7. iOS NSArray 的count方法返回的是无符号整形!

    ){ return cell; } 这样写是错误的!!!当数组为空时,由于count方法返回的是无符号整形,没有负数,self.requests.count -1是一个非常大的正数! 正确写法: &g ...

  8. 整型,长整型,无符号整型等 大端和小端(Big endian and Little endian)

    一.大端和小端的问题 对于整型.长整型.无符号整型等数据类型,Big endian 认为第一个字节是最高位字节(按照从低地址到高地址的顺序存放数据的高位字节到低位字节):而 Little endian ...

  9. char类型到底是有符号还是无符号

    根据c标准,char类型到底是有符号整数类型还是无符号整数类型,这取决于c实现,也就是c编译器的作者的想法:( 那么,如何快速的编写一个检测程序,查看当前编译器如何对char进行定义? #includ ...

随机推荐

  1. Html5 @media + css3 媒体查询

    css3 media媒体查询器用法总结   随着响应式设计模型的诞生,Web网站又要发生翻天腹地的改革浪潮,可能有些人会觉得在国内IE6用户居高不下的情况下,这些新的技术还不会广泛的蔓延下去,那你就错 ...

  2. Spring Boot Admin-应用健康监控后台管理

    Spring Boot Admin 用于监控基于 Spring Boot 的应用,它是在 Spring Boot Actuator 的基础上提供简洁的可视化 WEB UI. 1. 什么是Spring ...

  3. H3C 链路聚合分类

  4. 2018-10-23-使用-Pandoc-把-Markdown-转-Docx

    title author date CreateTime categories 使用 Pandoc 把 Markdown 转 Docx lindexi 2018-10-23 10:56:18 +080 ...

  5. 如何在iOS手机上进行自动化测试

    版权声明:允许转载,但转载必须保留原链接:请勿用作商业或者非法用途 Airtest支持iOS自动化测试,在Mac上为iOS手机部署iOS-Tagent之后,就可以使用AirtestIDE连接设备,像连 ...

  6. 2018-2-13-wpf-GifBitmapDecoder-解析-gif-格式

    title author date CreateTime categories wpf GifBitmapDecoder 解析 gif 格式 lindexi 2018-2-13 17:23:3 +08 ...

  7. apk混淆打包和反编译(转)

    前面有人写过了,我就直接引用了,大家就不乱找了.以后有问题再继续更新. 一.混淆打包.编译 1.Android 代码混淆.http://blog.csdn.net/zjclugger/article/ ...

  8. 记录安装Python第三方包“tesserocr”的方法和遇到的坑

    1. 环境: 系统环境:Win7 32 位系统 Python版本: 3.6.5        虚拟环境为:Miniconda3 2. 共需要安装的模块: a. tesserocr b. tessera ...

  9. 并查集的超市问题---溜TM的

    三个月前我就错了,现在又错了,我就是个傻****** 服了,看图哇 打扰了... #include<cstdio> #include<iostream> #include< ...

  10. Python学习3月5号【python编程 从入门到实践】---》笔记(3)4

    1.字典 #####修改字典里面的KEYS数值和VALUES数值要用中括号# alien_0={'color':'green','point':5}# alien_0['color']='red'# ...