Find The Multiple
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 16995   Accepted: 6921   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

【题目大意】

给出一个整数n,(1 <= n <= 200)。求出任意一个它的倍数m,要求m必须只由十进制的'0'或'1'组成。

【题目分析】

数论 +bfs

用到了同余定理,用bfs搜索当前位,每位都只可能是0或1,所以这是双入口的bfs,同时还涉及到了大数的知识。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;
int mod[];
int main(int i)
{
int n;
while(cin>>n)
{
if(!n)
break; mod[]=%n;
for(i=;mod[i-]!=;i++)
mod[i]=(mod[i/]*+i%)%n;
i--;
int pm=;
while(i)
{
mod[pm++]=i%;
i/=;
}
while(pm)
cout<<mod[--pm]; //倒序输出
cout<<endl;
}
return ;
}

数论 - 同余 + BFS (Find The Multiple)的更多相关文章

  1. hdu 1664(数论+同余搜索+记录路径)

    Different Digits Time Limit: 10000/4000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  2. 洛谷P1602 Sramoc问题 题解报告【同余+bfs】

    题目描述 话说员工们整理好了筷子之后,就准备将快餐送出了,但是一看订单,都傻眼了:订单上没有留电话号码,只写了一个sramoc(k,m)函数,这什么东西?什么意思?于是餐厅找来了资深顾问团的成员,YQ ...

  3. LightOJ1214 Large Division 基础数论+同余定理

    Given two integers, a and b, you should check whether a is divisible by b or not. We know that an in ...

  4. 51nod 1433 0和5【数论/九余定理】

    1433 0和5 题目来源: CodeForces 基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题  收藏  关注 小K手中有n张牌,每张牌上有一个一位数的数,这个 ...

  5. FZU 1057 a^b 【数论/九余定理】

    Accept: 1164    Submit: 3722Time Limit: 1000 mSec    Memory Limit : 32768 KB Problem Description 对于任 ...

  6. 【斐波拉契+数论+同余】【ZOJ3707】Calculate Prime S

    题目大意: S[n] 表示 集合{1,2,3,4,5.......n} 不存在连续元素的子集个数 Prime S 表示S[n]与之前的所有S[i]互质; 问 找到大于第K个PrimeS 能整除X 的第 ...

  7. HDU(4394),数论上的BFS

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4394 思路很巧妙,要找到m,可以这样思考,n的个位是有m的个位决定的,从0-9搜一遍,满足情况的话就继 ...

  8. 数论同余学习笔记 Part 2

    逆元 准确地说,这里讲的是模意义下的乘法逆元. 定义:如果有同余方程 \(ax\equiv 1\pmod p\),则 \(x\) 称为 \(a\bmod p\) 的逆元,记作 \(a^{-1}\). ...

  9. Least Common Multiple (HDU - 1019) 【简单数论】【LCM】【欧几里得辗转相除法】

    Least Common Multiple (HDU - 1019) [简单数论][LCM][欧几里得辗转相除法] 标签: 入门讲座题解 数论 题目描述 The least common multip ...

随机推荐

  1. Sliding Window Median

    Description Given an array of n integer, and a moving window(size k), move the window at each iterat ...

  2. 洛谷2051 [AHOI2009]中国象棋

    题目链接 题意概述:n行m列棋盘放若干个棋子每行每列最多两个求方案总数,答案对9999973取模. 可以比较容易看出这是个dp,设f[i][j][k]表示前i行j列放1个棋子k列放2个棋子的方案总数. ...

  3. Java如何获取当前类路径

    1.如何获得当前文件路径 常用: (1).Test.class.getResource("") 得到的是当前类FileTest.class文件的URI目录.不包括自己! (2).T ...

  4. Java编程思想之四控制执行流程

    程序必须再执行过程中控制它的世界,并做出选择.在Java中,你要使用执行控制语句来做出选择. 4.1true和false 所有条件语句都利用条件表达式的真或假来决定执行路径. Java不允许使用数字作 ...

  5. 使用Signature Tool自动生成P/Invoke调用Windows API的C#函数声明【转】

    原文链接:https://blog.csdn.net/Donjuan/article/details/3865026在网上看到很多网友在.NET程序中调用Win32 API,或者调用自己的VC DLL ...

  6. unix udp sendto 最大可发送的数据长度

    sendto 的最大可发送数据长度受限于两个值. 第一 [2^16 -1 - 8 -20] 第二 [SO_SNDBUF] 解释受限于[2^16-1-8-20] 数据封装过程 第一步: 用户层 : us ...

  7. Python爬虫实例项目

    WechatSogou [1]- 微信公众号爬虫.基于搜狗微信搜索的微信公众号爬虫接口,可以扩展成基于搜狗搜索的爬虫,返回结果是列表,每一项均是公众号具体信息字典. DouBanSpider [2]- ...

  8. boot2docker

    boot2docker 简介 boot2docker是解决非linux系统下运行Docker容器不方便的工具 官方介绍 Boot2Docker是在Windows操作系统上运行Docker的唯一方法,现 ...

  9. Promise和Observable的映射

    前言 promise解决了嵌套地狱的问题,Observable解决了promise只有一个结果,和不可以取消的问题. 使用的是rxjs6版本. 这篇文章是方便使用Observable的API替换Pro ...

  10. 荔枝派zero从焊接到跑起linux

    步骤 焊flash芯片(如果大于16M,需要改烧录工具的源码) 焊引脚,为了串口看数据 焊接flash芯片,需要注意1号脚的位置,flash芯片在开发板背面,1号脚位置是靠近麦克风的那边 以下为编译相 ...