题目链接:

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. Linux(CentOS6.5)下编译安装MySQL Community Server 5.7.12

      组件 官方网站 直接下载地址 备注 mysql http://dev.mysql.com/downloads/mysql/ http://mirrors.sohu.com/mysql/MySQL- ...

  2. php 理解

    <?php class t { var $num; var $dynamic_function; public function dynamic_function() { $func = $th ...

  3. Effective Java 第三版——14.考虑实现Comparable接口

    Tips <Effective Java, Third Edition>一书英文版已经出版,这本书的第二版想必很多人都读过,号称Java四大名著之一,不过第二版2009年出版,到现在已经将 ...

  4. Android 中adb 命令(实用)

    1. 用命令的方式打开关闭mtklog adb  shell am broadcast -a com.mediatek.mtklogger.ADB_CMD -e cmd_name start/stop ...

  5. duilib基本框架

    最近我一个同学在项目中使用到了duilib框架,但是之前并没有接触过,他与我讨论这方面的内容,看着官方给出的精美的例子,我对这个库有了很大的兴趣,我自己也是初学这个东东,我在网上花了不少时间来找相关的 ...

  6. RichErp - export import 用法

    // --file.js-- function getJSON(url, callback) { let xhr = new XMLHttpRequest(); xhr.onload = functi ...

  7. 内网IP无法访问

    就是我们在3类地址中常见到内网的IP段. 10.0.0.0--10.255.255.255 172.16.0.0--172.31.255.255 192.168.0.0--192.168.255.25 ...

  8. 使用js对form表单base64加密

    利用js可以对前台数据加密,以防止被恶意获取,以下代码,用base64对数据进行加密,可以在后台进行解密. 引入的js <script type="text/javascript&qu ...

  9. Inno Setup 自定义界面心得

    因为项目需要,需要打 windows 安装包,要求安装界面完全按照需求来.作为没接触过这块儿的服务端宝宝,在此期间踩了很多坑. 坑不提也罢,最终结果圆满,记录下与大部分网上PO出来的做法不太一样的小心 ...

  10. Android基础_BroadcastReceiver

    一:什么是BroadcastReceiver Broadcast(广播)是一种广泛运用于在应用程序之间一步传播消息的机制系统消息Android系统发出的,电池不足.来电信息等自定义消息第三方应用发出的 ...