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? ...
随机推荐
- Django之真正创建一个django项目
真正创建一个django项目 1 创建Django项目 :new-project 2 创建APP : python manager.py startapp app01 3 setting 配 ...
- canvas绘图,html5 k线图,股票行情图
canvas绘图,html5 k线图,股票行情图 canvas跟其他标签一样,也可以通过css来定义样式.但这里需要注意的是:canvas的默认宽高为300px * 150px,在css中为canva ...
- Qt 之 模态、非模态、半模态窗口的介绍及 实现QDialog的exec()方法
一.简述 先简单介绍一下模态与非模态对话框. 模态对话框 简单一点讲就是在弹出模态对话框时,除了该对话框整个应用程序窗口都无法接受用户响应,处于等待状态,直到模态对话框被关闭.这时一般需要点击对话框中 ...
- 问题 1084: 用筛法求之N内的素数。
#include <iostream> #include <cstdio> #include <cstring> #include <string> # ...
- 75.Java异常处理机制-自定义异常
package testDate; //自定义异常 public class MyException extends Exception{ public MyException(){ } public ...
- Codeforce 507B - Amr and Pins
Amr loves Geometry. One day he came up with a very interesting problem. Amr has a circle of radius r ...
- Service_name 和Sid的区别
Service_name:该参数是由oracle8i引进的.在8i以前,使用SID来表示标识数据库的一个实例,但是在Oracle的并行环境中,一个数据库对应多个实例,这样就需要多个网络服务名,设置繁琐 ...
- 怎样从外网访问内网SQLServer数据库?
本地安装了一个SQLServer数据库,只能在局域网内访问到,怎样从外网也能访问到本地的SQLServer数据库呢?本文将介绍具体的实现步骤. 1. 准备工作 1.1 安装并启动SQLServer数据 ...
- Android Camera2 预览,拍照,人脸检测并实时展现
https://www.jianshu.com/p/5414ba2b5508 背景 最近需要做一个人脸检测并实时预览的功能.就是边检测人脸,边在预览界面上框出来. 当然本人并不是专门做 ...
- Eloquent JavaScript #06# class
索引 Notes this Prototype 类 class符号 覆盖派生属性 Maps Symbols iterator接口 Getters, setters, and statics 继承 in ...