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

2
6
19
0

Sample Output

10
100100100100100100
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;

#include<stdio.h>
#define N 600000
int mod[N];
int ans[200];
int main()
{
int i,k,n;
while(scanf("%d",&n),n)
{
mod[1]=1%n;
for(i=2;mod[i-1]!=0;i++)
{
mod[i]=(mod[i/2]*10+i%2)%n;
}
i--;
k=0;
while(i)
{
ans[k++]=i%2;
i/=2;
}
for(i=k-1;i>=0;i--)
printf("%d",ans[i]);
puts("");
}
return 0;
}

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. 小程序01 微信小程序介绍和开发准备

    前言 火爆的微信小程序:跳一跳.摩拜单车.美柚.大众点评.滴滴出行 背景 为什么会有小程序? 微信最早推出公众号和服务号,公众号和服务号所传播的网页经常出现加载缓慢甚至页面空白的情况. 微信小程序的诞 ...

  2. Maven实战读书笔记(六):Maven灵活构建

    Maven为了支持构建的灵活性,内置了3大特性,即:属性.Profile和资源过滤. 6.1 Maven属性 Maven的属性与Java代码的常量有异曲同工之妙,都是为了消除重复,对相关内容进行统一管 ...

  3. Java Thread.join()详解

    一.使用方式. 二.为什么要用join()方法 三.join方法的作用 join 四.用实例来理解 打印结果: 打印结果: 五.从源码看join()方法   一.使用方式. join是Thread类的 ...

  4. java 生成二维码工具

    二维码生成 Gitee:https://gitee.com/search?utf8=%E2%9C%93&search=qrext4j&group_id=&project_id= ...

  5. MySQL配置索引页的合并阈值

    MySQL配置索引页的合并阈值 如果删除行或者通过UPDATE操作缩短行 可以为索引页面配置MERGE_THRESHOLD值. 当delete与update缩短了行长度时,索引页的"page ...

  6. python全套视频十五期(116G)

    python全套视频,第十五期,从入门到精通,基础班,就业班,面试,软件包 所属网站分类: 资源下载 > python视频教程 作者:精灵 链接:http://www.pythonheidong ...

  7. python_面向对象笔记

    继承 什么是继承? 继承是一种新建类的方式,新建的类称为子类或派生类父类又称为基类.超类 子类可以“遗传”父类的属性,从而可以减少代码冗余 如何寻找继承关系?先抽象,再继承,继承描述的就是一种父子关系 ...

  8. P1880 NOIP 1995石子合并

    复习(du) 这道题,发现思想真不错 当时背板子打下来的 要下晚自习了,明天更注释吧 #include<iostream> #include<queue> #include&l ...

  9. 在java中获取Map集合中的key和value值

  10. NYOJ301-递推求值

    递推求值 nyoj上矩阵专题里的10道题水了AC率最高的5道,惭愧,还不是完全自己写的,用了几乎两周的时间.模板题我是有自信写出来的,但对于高级一点的矩阵构造,我还是菜的抠脚. 这题感谢MQL大哥和她 ...