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. smashing 开源方便的dashboard 试用

    smashing 一个方便的dashboard 工具,是在Shopify/dashing 上维护的一个版本因为原有的官方团队不在维护了 smashing 使用简单,提供了脚手架同时也有好多人开发了一些 ...

  2. 20181107 模拟赛T1:快乐传递政治正确版

    问题描述 David 有很多好朋友.有些期末季刚结束,有些人很快乐,但有些不太快乐,David 想把快乐传递给每个人,作为心理学大师,他准备了如下计划:David 的朋友中有 n 个男生和 m 个女生 ...

  3. 中国大学生计算机系统与程序设计竞赛 CCF-CCSP-2017 串行调度(serial)

    串行调度(serial) 除等价条件, 根据题意设置限制条件,然后求字典序最小拓扑序. 简洁版 #include<bits/stdc++.h> using namespace std; ; ...

  4. 假设检验总结以及如何用python进行假设检验(scipy)

    几种常见的假设检验总结如下: 假设检验名称 Z检验 t检验 χ2检验 F检验 原假设 H0: μ≥μ0        H0: μ≤μ0        H0: μ=μ0  (比较样本和总体均值)     ...

  5. 【luoguP1858】多人背包

    链接 对于每个状态\(f[j]\)多记录一个维度,转移的时候利用类似于归并排序的方法合并,以保证时间复杂度可以承受 注意事项:前\(K\)大可以有重复的价值 #include<iostream& ...

  6. linux实现pwd

    版本1: 调用系统接口getcwd,实现路径打印. /*** ***文件名:1_mypwd.c ***描述:通过系统函数getcwd实现pwd命令 ***/ #include<stdio.h&g ...

  7. 关于golang-mod的使用方法

    简单粗暴仅需要三步即可 $ go mod download $ go mod tidy $ go build -v 这里保持默认什么都不用添加,项目无需在 gopath里面 Vendoring mod ...

  8. iptables只允许指定ip访问本机的指定端口

    首先,清除所有预设置 iptables -F 其次,设置只允许指定ip地址访问指定端口 1.在tcp协议中,禁止所有的ip访问本机的1521端口. iptables -I INPUT -p tcp - ...

  9. 使用Rome读取RSS报错,org.xml.sax.SAXParseException: 前言中不允许有内容。

    这是我遇到过的最奇葩的错误 new URL的时候,使用静态变量就会报错org.xml.sax.SAXParseException: 前言中不允许有内容. URL url = new URL(Strin ...

  10. C# 简单通信(实现文件传输)

    https://blog.csdn.net/Sayesan/article/details/82185772 之前写过一个简单通信传输,不过只有聊天的功能,现在实现了文件传输的功能,借鉴于网上一篇博客 ...