题目链接:

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. MySql监控优化

    MySQL监控   MySQL服务器硬件和OS(操作系统)调优:   1.有足够的物理内存,能将整个InnoDB文件加载到内存里 —— 如果访问的文件在内存里,而不是在磁盘上,InnoDB会快很多. ...

  2. 【开源】AspnetCore 2.0 自动API文档生成组件,支持protobuffer

    本文地址 http://www.cnblogs.com/likeli/p/8204054.html 关于 API文档自动生成,用于对APP端的开发帮助文档生成,默认ProtoBuffer传输格式. 本 ...

  3. Head First设计模式之解释器模式

    一.定义 给定一个语言,定义它的文法表示,并定义一个解释器,这个解释器使用该标识来解释语言中的句子. 主要解决:对于一些固定文法构建一个解释句子的解释器. 何时使用:如果一种特定类型的问题发生的频率足 ...

  4. Micropython实例之TPYBoard来电显示功能演示

    一.TPYBoardV702介绍 TPYBoardV702是目前市面上唯一支持通信通信功能的MicroPython开发板:支持Python3.0及以上版本直接运行.支持GPS+北斗双模通信.GPRS通 ...

  5. TurnipBit—MicroPython开发板:妥妥拽拽零基础也能玩编程

    可视化编程网站入口:www.turnipbit.com 说到编程.谈到硬件,你也许会想到屌丝逆袭女神的"传奇"故事,也许会浮现出带着眼镜.头发稀少.无精打采的程序猿形象." ...

  6. python基础(六)dict字典和文件操作open

    字典dict 使用key来标注value的数据类型,key和value是一一对应的.在字典中key是唯一的,所以字典也是无序的. #定义一个字典 dict = { 'name' : 'sylar', ...

  7. 利用appium-1.5.3.dmg安装Appium. doctors时,提示 Could not detect Mac OS X Version from sw_vers output: '10.12'

    发生这种错误的原因是因为:appium不支持mac 10.12版本. 解决方法: https://stackoverflow.com/questions/40129794/how-to-fix-err ...

  8. JavaScript(jquery)实现二级菜单联动

    为什么写这篇随笔? 二级菜单的联动一直是我心中一块石头,犹记得大一的时候只会用一点的Dreamweaver,当时做二级菜单难受啊,啥都不会,网上找了些资料,也看不懂别人的代码更别说用起来了 前些日子. ...

  9. Ubuntu设置程序开机自启或者开机禁止加载

    先说说ubuntu,它有运行级别这个概念 0:停机 1:单用户形式,只root进行维护 2:多用户,不能使用net file system 3:完全多用户 5:图形化 6:重启 例子:按指定顺序.在指 ...

  10. [转载]常见slave 延迟原因以及解决方法

    一  序言在运维线上M-M 架构的MySQL数据库时,接收的比较多关于主备延时的报警: 点击(此处)折叠或打开 check_ins_slave_lag (err_cnt:1)critical-slav ...