题目链接:

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

2
6
19
0

Sample Output

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

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

#include<stdio.h>
#define N 600000
int mod[N];
int ans[];//根据情况增大数组
int main()
{
int i,k,n,j;
while(scanf("%d",&n),n)
{
mod[]=%n;
for(i=;mod[i-]!=;i++)
mod[i]=(mod[i/]*+i%) %n;
//printf("i-1=%d\n",i-1);
i--;
k=;
while(i)
{
ans[k++]=i%;
i/=;
}
for(i=k-;i>=;i--)
printf("%d",ans[i]);
puts("\n");
}
return ;
}

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. java操作时间,将当前时间减一年,减一天,减一个月

    在Java中操作时间的时候,常常遇到求一段时间内的某些值,或者计算一段时间之间的天数 Date date = new Date();//获取当前时间 Calendar calendar = Calen ...

  2. ExpandableListView的完美实现,JSON数据源,右边自定义图片

    转载请标明出处: http://www.cnblogs.com/dingxiansen/p/8194669.html 本文出自:丁先森-博客园 最近在项目中要使用ExpandableListView来 ...

  3. 分享非常好用的前端分页js工具类 灵活 简单易懂

    分享自己封装的前端分页js工具类  下面是默认样式效果截图 可以随意更改js及css 很灵活 /** * pageSize, 每页显示数 * pageIndex, 当前页数 * pageCount 总 ...

  4. How to setup a DL4J project with eclipse

    https://electronsfree.blogspot.com/2016/10/how-to-setup-dl4j-project-with-eclipse.html

  5. dom4j 间隔插入节点 处理复杂的xml文档

    前几周跟着老师做了一个小项目,个人主要负责xml文档处理,处理过程还是比较复杂的.此外这篇文章并不是讲基本的dom4j读写xml文档, 所以阅读此文的前提是你已经有了dom4j或jdom等处理xml文 ...

  6. 2.Text input and output

    文本的输入和输出 输出 要在屏幕上输出文本你需要这样一行代码: print("Hello World") 如果输出多行,要添加符号“\n”: print("Hello W ...

  7. 《JAVA程序设计与实例》记录与归纳--继承与多态

    继承与多态 概念贴士: 1. 继承,即是在已经存在的类的基础上再进行扩展,从而产生新的类.已经存在的类成为父类.超类和基类,而新产生的类成为子类或派生类. 2. Java继承是使用已存在的类的定义作为 ...

  8. 原生js选项卡

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  9. 搞懂spring事务

    最近一个官网的项目,我在service层有两个添加数据的操作,很意外报错了,然后就研究到了事务 之前只是知道声明式事务和编程式事务,编程式的事务显得比较麻烦,一般都是使用声明式事务.. spring提 ...

  10. ISE14.7兼容性问题集锦

    六.WARNING:iMPACT:923 - Can not find cable, check cable setup ! 这个错误是由于驱动没有安装或者驱动安装有问题,一般ISE会在安装的时候把驱 ...