题目链接:

http://poj.org/problem?id=1426

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
    题意描述:
    输入(1 <= n <= 200)
    输出一个由01组成的数并且能够被n整除
    解题思路:
    看了题解有了一些思路,用mod[i]=mod[i/2]*10+i%2;这个式子计算二进制i在十进制的形式并存进mod[i]数组,所以使用long long 定义mod数组,很容易理解
  1. #include<stdio.h>
  2. long long mod[];
  3. int main()
  4. {
  5. int n;
  6. while(scanf("%d",&n),n)
  7. {
  8. int i;
  9. for(i=; mod[i-]%n != ;i++)
  10. mod[i]=mod[i/]*+i%;// mod[i]表示十进制形式的二进制i
  11. printf("%I64d\n",mod[i]);
  12. }
  13. return ;
  14. }

但是延伸一下,如果超过200或者更大呢,请参考

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

POJ 1426 Find The Multiple(数论——中国同余定理)的更多相关文章

  1. POJ 1426 Find the Multiple 思路,线性同余,搜索 难度:2

    http://poj.org/problem?id=1426 测试了一番,从1-200的所有值都有long long下的解,所以可以直接用long long 存储 从1出发,每次向10*s和10*s+ ...

  2. (简单) POJ 1426 Find The Multiple,BFS+同余。

    Description Given a positive integer n, write a program to find out a nonzero multiple m of n whose ...

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

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

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

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

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

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

  6. POJ.1426 Find The Multiple (BFS)

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

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

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

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

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

  9. POJ 1426 Find The Multiple (dfs??!!)

    Description Given a positive integer n, write a program to find out a nonzero multiple m of n whose ...

随机推荐

  1. 使用Linux 安装MySQL

    文章  link 在安装mysql数据库服务器前,确保你的linux系统是可以连接网络的,下面我们将通过源码方式来安装mysql首先通过putty登入进你的Linux系统,确保系统中已经安装的gcc ...

  2. 30分钟入门Java

    技术只是工具,文档只是说明书,仅此而已. 写在前面 工作4年有余,盲人摸象般的走过弯路,也投机取巧的领悟到过一些类似"编程本质"的东西.现在开始我计划回顾下我的编程生涯.在这里分享 ...

  3. touch监听判断手指的上滑,下滑,左滑,右滑,事件监听

    判断滑动的方向和距离,来实现一定的效果,比如返回上一页等等 <body> <script> $(function(){ //给body强制定义高度 var windowHeig ...

  4. QA问答系统,QA匹配论文学习笔记

    论文题目: WIKIQA: A Challenge Dataset for Open-Domain Question Answering 论文代码运行: 首先按照readme中的提示安装需要的部分 遇 ...

  5. beanstalk 安装

    1.安装 # wget https://github.com/kr/beanstalkd/archive/v1.10.tar.gz # tar xzvf v1.10 # cd beanstalkd-1 ...

  6. 关于 Python 入门的一些问题?

    一.用 python 能够做什么?解决什么问题? A1:理论上来说,计算机能做什么,python 语言就能让它做什么,也即 python能做什么. 数值计算.机器学习.爬虫.云相关开发.自动化测试.运 ...

  7. 计算机基础理论知识梳理篇(三):VLAN与VLAN网卡相关概念

    VLAN(Virtual Local Area Network) 虚拟局域网(VLAN,802.1Q)是一组逻辑上的设备和用户,这些设备和用户并不受物理位置的限制,可以根据功能.部门及应用等因素将它们 ...

  8. docker:(3)docker容器挂载宿主主机目录

    有一项重要的参数 -v 目录挂载,就是让容器内部目录和宿主主机目录关联起来,这样就可以直接操作宿主主机目录而不用再操作具体容器了 比如在2中,我们要发布一个war包,是通过 sudo docker c ...

  9. flask WTForms源码分析及自定义WTForms

    首先我们来创建一个From类 from wtforms.form import Form from wtforms import StringField from wtforms.validators ...

  10. 使用Java内置的Http Server构建Web应用

    一.概述 使用Java技术构建Web应用时, 我们通常离不开tomcat和jetty之类的servlet容器,这些Web服务器功能强大,性能强劲,深受欢迎,是运行大型Web应用的必备神器. 虽然Jav ...