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. 2018-8-10-用-sim-卡加密保护资金

    title author date CreateTime categories 用 sim 卡加密保护资金 lindexi 2018-08-10 19:16:52 +0800 2018-2-13 17 ...

  2. 【a602】最大乘积

    Time Limit: 1 second Memory Limit: 32 MB [问题描述] 一个正整数一般可以分为几个互不相同的自然数的,如3=1+2,4=1+3,5=1+4=2+3,6=1+5= ...

  3. 【hdu 1112】The Proper Key

    Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s) ...

  4. 2018-8-10-win10-uwp-绘图--Line-控件使用

    title author date CreateTime categories win10 uwp 绘图 Line 控件使用 lindexi 2018-08-10 19:16:51 +0800 201 ...

  5. win10 uwp 在 VisualStudio 部署失败,找不到 Windows Phone 可能的原因

    在我使用 VisualStudio 调试的时候,发现我插入了手机,但是 VisualStudio 在部署的时候找不到手机. 可能的原因是 手机禁用了连接,第二个原因是可能手机驱动没正确让 Visual ...

  6. H3C IPv6地址自动配置

  7. 新手该如何学习JavaScript ?

    JavaScript入门 - 01 准备工作 在正式的学习JavaScript之前,我们先来学习一些小工具,帮助我们更好的学习和理解后面的内容. js代码位置 首先是如何编写JavaScript代码, ...

  8. H3C 链路聚合的作用

  9. H3C调试信息输出的例子

  10. linux 阻塞 open 作为对 EBUSY 的替代

    当设备不可存取, 返回一个错误常常是最合理的方法, 但是有些情况用户可能更愿意等待 设备. 例如, 如果一个数据通讯通道既用于规律地预期地传送报告(使用 crontab), 也用于根据 用户的需要偶尔 ...