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. /proc文件系统的特点和/proc文件的说明

    /proc文件系统是一种特殊的.由软件创建的文件系统,内核使用它向外界导出信息,/proc系统只存在内存当中,而不占用外存空间. /proc下面的每个文件都绑定于一个内核函数,用户读取文件时,该函数动 ...

  2. ent 基本使用十五 一个图遍历的例子

    以下是来自官方的一个user group pet 的查询demo 参考关系图 环境准备 docker-compose mysql 环境 version: "3" services: ...

  3. 编译lua固件NodeMcu 8266

    https://www.cnblogs.com/yangfengwu/p/10547024.html 因为我现在的Wifi的教程是lua语言编写的,但是有些功能需要自己编译lua固件才可以,这篇文章就 ...

  4. CCF 201709-3 JSON查询

    CCF 201709-3 JSON查询 试题编号: 201709-3 试题名称: JSON查询 时间限制: 1.0s 内存限制: 256.0MB 问题描述: 问题描述 JSON (JavaScript ...

  5. string类的用法总结

    string中常见的成员函数 示例代码: string s= string("abcdefg"); char ch[] = "abcdefgd"; //调用构造 ...

  6. UDF——Fluent与Matlab数据耦合

    本文编译工具:VC++ UDF Studio 该插件可以直接在Visual Studio中一键编译.加载.调试UDF源码,极大提高编写排错效率,且支持C++,MFC,Windows API和第三方库, ...

  7. <每日 1 OJ> -LeetCode 7. 整数反转

    题目描述 给定一个 32 位有符号整数,将整数中的数字进行反转. 示例 1: 输入: 123 输出: 321  示例 2: 输入: -123 输出: -321 示例 3: 输入: 120 输出: 21 ...

  8. kafka(五) 流式处理 kafka stream

    参考文档: http://www.infoq.com/cn/articles/kafka-analysis-part-7?utm_source=infoq&utm_campaign=user_ ...

  9. [技术博客]windows中使用docker技术

    背景 我们的工程使用了一个叫做termux的安卓上的linux终端,这个终端在所有的软件包里硬编码了软件的运行路径(/data/data/com.termux/..),由于安卓系统的权限设计,我们名为 ...

  10. 5G网络类型 ?

    TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SE ...