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.

  1. 给定一个整数n,敲个代码来找出n的仅有数字01构成的非零倍数m。你可以认为n不超过200m不超过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.

  1. 多组测试用例。每行有一个数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.

  1. 对于每个输入的n,输出一行m。十进制数m必须不能超过100位。如果对于n存在多解,则随便输出一种。

CN

Sample Input - 输入样例

  1. 2
  2. 6
  3. 19
  4. 0

Sample Output - 输出样例

  1. 10
  2. 100100100100100100
  3. 111111111111111111

题解

  刚刚开始在想直接2^100可能有点问题,打算模拟除法来做…………然而水平太渣,写条件真是要死要活。(虽然可以出结果但是回溯/转移的时候没考虑好导致长度有问题……)
  发觉讨论里表示可以直接暴力出来……然后发现…………居然可以?!
  (估计数据不多)
  从100位开始发现可以刚好剪到19位,int64范围。
  不过似乎由于编译器对自动转换的支持问题,提交的时候要手动弄好int64才可以。

代码 C++

  1. #include <cstdio>
  2. __int64 isFid, n;
  3. void DFS(__int64 now, int len){
  4. if (!isFid || len > ) return;
  5. if (isFid = now%n){
  6. DFS(now * , len + ); DFS(now * + , len + );
  7. }
  8. else printf("%I64d\n", now);
  9. }
  10. int main(){
  11. while (scanf("%I64d", &n), isFid = n) DFS(, );
  12. return ;
  13. }

POJ 1426 Find The Multiple(寻找倍数)的更多相关文章

  1. POJ 1426 Find The Multiple --- BFS || DFS

    POJ 1426 Find The Multiple 题意:给定一个整数n,求n的一个倍数,要求这个倍数只含0和1 参考博客:点我 解法一:普通的BFS(用G++能过但C++会超时) 从小到大搜索直至 ...

  2. POJ.1426 Find The Multiple (BFS)

    POJ.1426 Find The Multiple (BFS) 题意分析 给出一个数字n,求出一个由01组成的十进制数,并且是n的倍数. 思路就是从1开始,枚举下一位,因为下一位只能是0或1,故这个 ...

  3. 广搜+打表 POJ 1426 Find The Multiple

    POJ 1426   Find The Multiple Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 25734   Ac ...

  4. DFS/BFS(同余模) POJ 1426 Find The Multiple

    题目传送门 /* 题意:找出一个0和1组成的数字能整除n DFS:200的范围内不会爆long long,DFS水过~ */ /************************************ ...

  5. POJ 1426 Find The Multiple (DFS / BFS)

    题目链接:id=1426">Find The Multiple 解析:直接从前往后搜.设当前数为k用long long保存,则下一个数不是k*10就是k*10+1 AC代码: /* D ...

  6. POJ 1426 Find The Multiple &amp;&amp; 51nod 1109 01组成的N的倍数 (BFS + 同余模定理)

    Find The Multiple Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 21436   Accepted: 877 ...

  7. 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 ...

  8. POJ 1426 Find The Multiple(数论——中国同余定理)

    题目链接: http://poj.org/problem?id=1426 Description Given a positive integer n, write a program to find ...

  9. POJ - 1426 Find The Multiple(搜索+数论)

    转载自:優YoU  http://user.qzone.qq.com/289065406/blog/1303946967 以下内容属于以上这位dalao http://poj.org/problem? ...

随机推荐

  1. activiti 报 next dbid

    记录一下吧. 今天将生产环境的几个服务节点改成集群模式,其中包含activiti审批服务节点,其中各个服务几点间数据通信采用MQ(与本文无关). 然后报出如题错误. 究其原因就是,在启动activit ...

  2. Django ORM 操作 必知必会13条 单表查询

    ORM 操作 必知必会13条 import os # if __name__ == '__main__': # 当前文件下执行 os.environ.setdefault('DJANGO_SETTIN ...

  3. bzoj2287 [POJ Challenge]消失之物

    题目链接 少打个else 调半天QAQ 重点在47行,比较妙 #include<algorithm> #include<iostream> #include<cstdli ...

  4. [转载]oracle树形查询 start with connect by

    一.简介 在oracle中start with connect by (prior) 用来对树形结构的数据进行查询.其中start with conditon 给出的是数据搜索范围, connect ...

  5. Nginx rewrite(重写)

    Nginx Rewrite规则相关指令  Nginx Rewrite规则相关指令有if.rewrite.set.return.break等,其中rewrite是最关键的指令.一个简单的Nginx Re ...

  6. 如何解决win10关机状态下,按键盘会自动开机的问题

    关机状态下按下键盘会自动开机,是因为所装的系统默认设置了快速启动功能 下面是关闭快速启动的方法: 步骤一: 在win10桌面右击,点击显示设置 步骤二: 电源和睡眠-->其他电源设置 步骤三: ...

  7. intelliJ IDEA之使用svn或git管理代码

    intelliJ IDEA之使用svn管理代码 1.VCS—>import into Version Control—>Share Project(Subversion) 2.点击+    ...

  8. Golang生成区间随机整数

    package main import ( "fmt" "math/rand" "time" ) func main() { rand.Se ...

  9. Bootstrap表单样式

    <form class="form-horizontal" role="form"> <fieldset> <legend> ...

  10. JavaScript数组实现图片轮播

    最终效果 注:图片来源于百度图片 文件结构: 代码: <!DOCTYPE html> <html> <head> <meta charset="UT ...