POJ 1426 Find The Multiple
来源:互联网 发布:哈尔滨淘宝培训学校 编辑:程序博客网 时间:2024/06/04 20:05
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
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
题意:求出由1和0组成的N的倍数M,N是不大于200的数,M是小于100位的数
只要用深搜遍历即可,因为用long long只能存下19位数字,并且在long long以内可以找到符合条件的目标值。而n不大于200,所以只要判断在19位数字内是否存在目标值即可。
用f标记是否找到符合条件的m,s标记m的第几位。若f为真或s>18,return。只需要dfs(m*10,s+1)(m的第s位为0)和dfs(m*10+1,s+1)(m的第s位为1)就可以列举出所有状态,若m%n==0,标记f=1,return。
#include<stdio.h>int n,f;void dfs(long long int m,int s){ if(f||s>18) return ; if(m%n==0) { f=1; printf("%lld\n",m); } dfs(m*10,s+1); //第s位为0 dfs(m*10+1,s+1); //第s位为1}int main(){ while(~scanf("%d",&n)&&n) { f=0; dfs(1,0); } return 0;}
阅读全文
1 0
- poj 1426 Find The Multiple
- Poj 1426 Find The Multiple
- POJ 1426 Find the Multiple
- poj 1426Find The Multiple
- POJ 1426 Find The Multiple
- POJ 1426 Find The Multiple
- POJ 1426 Find The Multiple
- POJ 1426 Find The Multiple
- poj - 1426 - Find The Multiple
- POJ 1426 Find The Multiple
- POJ-1426-Find The Multiple
- POJ 1426 Find The Multiple
- POJ 1426 Find The Multiple
- POJ 1426 Find The Multiple
- POJ 1426 Find The Multiple
- POJ 1426 Find The Multiple
- poj 1426 Find The Multiple
- POJ 1426 Find The Multiple
- 基于地理位置的数据挖掘
- Android通过.nomedia文件禁止多媒体库扫描指定文件夹下的多媒体文件
- R语言genalg之suggestions参数
- spring boot 远程调试设置
- Linq与传统方法对比、遍历文件示例
- POJ 1426 Find The Multiple
- HtmlCleaner XPath API使用
- View侧滑动画
- android之如何开发app能在1M以下?
- jQuery的deferred对象使用详解
- fastjson @JSONField自定义输出字段
- jqGrid 两层表头
- 推荐一位大佬博客<关于记录淘淘商城开发点点滴滴>
- 自动检查顶点色、2U、ID、坐标轴的测试