Find The Multiple
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 18390   Accepted: 7445   Special Judge

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.

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

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

Sample Output

  1. 10
  2. 100100100100100100
  3. 111111111111111111

同余模定理:

(a*b)%n = (a%n *b%n)%n;

(a+b)%n = (a%n +b%n)%n;

枚举前14个数字为:1 、10 、11、100、101、110、111、1000、1001、1010、1011、1100、1101、1110。

。。

1110%6=(110*10+0)%6=((110%6)*10)%6+(0%6);

mod[x]=(mod[x/2]*10+x%2)%n;

  1. #include<stdio.h>
  2. #define N 600000
  3. int mod[N];
  4. int ans[200];
  5. int main()
  6. {
  7. int i,k,n;
  8. while(scanf("%d",&n),n)
  9. {
  10. mod[1]=1%n;
  11. for(i=2;mod[i-1]!=0;i++)
  12. {
  13. mod[i]=(mod[i/2]*10+i%2)%n;
  14. }
  15. i--;
  16. k=0;
  17. while(i)
  18. {
  19. ans[k++]=i%2;
  20. i/=2;
  21. }
  22. for(i=k-1;i>=0;i--)
  23. printf("%d",ans[i]);
  24. puts("");
  25. }
  26. return 0;
  27. }

poj 1426 Find The Multiple ( BFS+同余模定理)的更多相关文章

  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 搜索)

    Find The Multiple Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 18012   Accepted: 729 ...

  3. POJ 1426 Find The Multiple BFS

    没什么好说的 从1开始进行广搜,因为只能包涵0和1,所以下一次需要搜索的值为next=now*10 和 next=now*10+1,每次判断一下就可以了,但是我一直不太明白我的代码为什么C++提交会错 ...

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

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

  5. POJ.1426 Find The Multiple (BFS)

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

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

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

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

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

  8. POJ 1426 Find The Multiple(寻找倍数)

    POJ 1426 Find The Multiple(寻找倍数) Time Limit: 1000MS    Memory Limit: 65536K Description - 题目描述 Given ...

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

随机推荐

  1. myBatis参数处理 myBatis佟刚课程笔记

    单个参数:myBatis不会做特殊处理 #{参数名}: 取出参数值 多个参数: myBatis会做特殊处理 多个参数会被封装成一个MAP key:param1 param2.... param10,或 ...

  2. Eaton Char-Lynn Motor : Performance Of Small Displacement Motors

    The small-displacement supercharged motor replaces the large-displacement motor with the speed of li ...

  3. JavaSE-25 AWT

    学习要点 关于AWT AWT容器 布局管理器 AWT组件 事件处理 关于AWT java.awt包与子包 AWT软件包 说明 import  java.awt.*; 基本组件使用工具 import  ...

  4. 【JDBC】Servlet实例

    import java.io.IOException;import java.io.PrintWriter;import java.sql.Connection;import java.sql.Dri ...

  5. ubuntu14.04 RockMongo的配置

    安装php5 安装php5     sudo apt-get install php5 让Apache支持php      sudo apt-get install libapache2-mod-ph ...

  6. LINUX:关于Redis集群的节点分配

    文章来源:http://www.cnblogs.com/hello-tl/p/7808268.html 根据上述  Redis集群搭建:http://www.cnblogs.com/hello-tl/ ...

  7. 南邮CTF--SQL注入题

    南邮CTF--SQL注入题 题目:GBK SQL injection 解析: 1.判断注入点:加入单引号发现被反斜杠转移掉了,换一个,看清题目,GBK,接下来利用宽字节进行注入 2.使用'%df' ' ...

  8. HTML元素的基本特性

    1,Disabled 特性: //Disabled 设置元素不可用: $(this).attr("disabled","disabled") //移除push元 ...

  9. 『NYIST』第八届河南省ACM竞赛训练赛[正式赛一]-CodeForces 237C,素数打表,二分查找

    C. Primes on Interval time limit per test 1 second memory limit per test 256 megabytes input standar ...

  10. 【Kubernetes】Kubernetes的Service外部访问方式:NodePort和LoadBalancer

    Kubernetes的Pod的寿命是有限的,它们不会复活,因此尽管每个Pod都有自己的IP地址,但是这些IP地址是不可靠的,会随着Pod的消亡而消失. 这就带来一个问题,如果一些Pod的集合(称之为b ...