POJ 1426 Find The Multiple(寻找倍数)
POJ 1426 Find The Multiple(寻找倍数)
Time Limit: 1000MS Memory Limit: 65536K
Description - 题目描述
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.
给定一个整数n,敲个代码来找出n的仅有数字0和1构成的非零倍数m。你可以认为n不超过200且m不超过100个十进制数。
CN
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.
多组测试用例。每行有一个数n ( <= n <= )。某行一个0为输入结束。
CN
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.
对于每个输入的n,输出一行m。十进制数m必须不能超过100位。如果对于n存在多解,则随便输出一种。
CN
Sample Input - 输入样例
2
6
19
0
Sample Output - 输出样例
10
100100100100100100
111111111111111111
题解
刚刚开始在想直接2^100可能有点问题,打算模拟除法来做…………然而水平太渣,写条件真是要死要活。(虽然可以出结果但是回溯/转移的时候没考虑好导致长度有问题……)
发觉讨论里表示可以直接暴力出来……然后发现…………居然可以?!
(估计数据不多)
从100位开始发现可以刚好剪到19位,int64范围。
不过似乎由于编译器对自动转换的支持问题,提交的时候要手动弄好int64才可以。
代码 C++
#include <cstdio>
__int64 isFid, n;
void DFS(__int64 now, int len){
if (!isFid || len > ) return;
if (isFid = now%n){
DFS(now * , len + ); DFS(now * + , len + );
}
else printf("%I64d\n", now);
}
int main(){
while (scanf("%I64d", &n), isFid = n) DFS(, );
return ;
}
POJ 1426 Find The Multiple(寻找倍数)的更多相关文章
- POJ 1426 Find The Multiple --- BFS || DFS
POJ 1426 Find The Multiple 题意:给定一个整数n,求n的一个倍数,要求这个倍数只含0和1 参考博客:点我 解法一:普通的BFS(用G++能过但C++会超时) 从小到大搜索直至 ...
- POJ.1426 Find The Multiple (BFS)
POJ.1426 Find The Multiple (BFS) 题意分析 给出一个数字n,求出一个由01组成的十进制数,并且是n的倍数. 思路就是从1开始,枚举下一位,因为下一位只能是0或1,故这个 ...
- 广搜+打表 POJ 1426 Find The Multiple
POJ 1426 Find The Multiple Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 25734 Ac ...
- DFS/BFS(同余模) POJ 1426 Find The Multiple
题目传送门 /* 题意:找出一个0和1组成的数字能整除n DFS:200的范围内不会爆long long,DFS水过~ */ /************************************ ...
- POJ 1426 Find The Multiple (DFS / BFS)
题目链接:id=1426">Find The Multiple 解析:直接从前往后搜.设当前数为k用long long保存,则下一个数不是k*10就是k*10+1 AC代码: /* D ...
- POJ 1426 Find The Multiple && 51nod 1109 01组成的N的倍数 (BFS + 同余模定理)
Find The Multiple Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 21436 Accepted: 877 ...
- POJ 1426 - Find The Multiple - [DP][BFS]
题目链接:http://poj.org/problem?id=1426 Given a positive integer n, write a program to find out a nonzer ...
- POJ 1426 Find The Multiple(数论——中国同余定理)
题目链接: http://poj.org/problem?id=1426 Description Given a positive integer n, write a program to find ...
- POJ - 1426 Find The Multiple(搜索+数论)
转载自:優YoU http://user.qzone.qq.com/289065406/blog/1303946967 以下内容属于以上这位dalao http://poj.org/problem? ...
随机推荐
- qt5 移植 交叉编译出现错误
类似这样的错误,当时没有完整的记下来,undefined reference to `std::__detail::_List_node_base@GLIBCXX_3.4.10 当时是在编译qt5cl ...
- 微信小程序制作家庭记账本之六
第六天,自己根据样本代码做的记账本可实现添加账目,删除账目和消费总和,实机可以测试,但是没有域名,别人无法访问.
- JDK8 元空间
1. 运行时常量池和静态变量都存储到了堆中,MetaSpace存储类的元数据,MetaSpace直接申请在本地内存中(Native memory),这样类的元数据分配只受本地内存大小的限制,OOM问题 ...
- selenium-java web自动化测试工具抓取百度搜索结果实例
selenium-java web自动化测试工具抓取百度搜索结果实例 这种方式抓百度的搜索关键字结果非常容易抓长尾关键词,根据热门关键词去抓更多内容可以用抓google,百度的这种内容容易给屏蔽,用这 ...
- C++中set用法详解
1.关于set C++ STL 之所以得到广泛的赞誉,也被很多人使用,不只是提供了像vector, string, list等方便的容器,更重要的是STL封装了许多复杂的数据结构算法和大量常用数据结构 ...
- 爬虫--cheerio
const cheerio = require('cheerio') const $ = cheerio.load('<h2 class="title">Hello w ...
- django模型的crud操作
一个建立好的模型,django会生成一套完整的API,以便对对象进行crud操作,下面就详细介绍crud操作. 先说一下操作环境: python2.7, django1.11.8, win7系统,借助 ...
- 启动项详解和更改deepin启动内核的方法
内容来自网上查找和总结以及自己的尝试 boot里面的启动项是根据其它文件生成的,如果改boot里面,会在你更新grub后再次回到原来的状态.(之后 我(有显卡驱动问题的用户)通过在开机时选择系统页面按 ...
- PHP中array_map与array_column之间的关系分析
array_map()与array_column()用法如下: array_map();将回调函数作用到给定数组的单元上array_column();快速实现:将二维数组转为一维数组 array_co ...
- Java JDBC调用存储过程:无参、输入带参、输出及输出带参
Java JDBC调用存储过程:无参.输入带参.输出及输出带参 示例代码: package xzg; import java.sql.CallableStatement; import java.sq ...