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

Source

题意:找出一个最小的由1或者0组成的十进制数能整除n
题解:dfs,一开始看题目说十进制数会达到100位,其实不会,在longlong的范围内,下次遇到这种可以直接打表找一下规律
代码:
#include<iostream>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
const ll mod=;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
//head
#define MAX 1000
int n;
int flag;
void dfs(int cur,ll sum)
{
if(cur==)return ;
if(flag) return ;
if(sum%n==&&sum!=)
{
flag=;
cout<<sum<<endl;
return ;
}
else
dfs(cur+,sum*),dfs(cur+,sum*+);
}
int main()
{
cin.tie();
cout.tie();
ios::sync_with_stdio();
while(cin>>n)
{
if(n==)break;
flag=;
dfs(,);
}
return ;
}

poj1426 Find The Multiple (DFS)的更多相关文章

  1. POJ1426——Find The Multiple

    POJ1426--Find The Multiple Description Given a positive integer n, write a program to find out a non ...

  2. poj1426 Find The Multiple(c语言巧解)

    Find The Multiple Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 36335   Accepted: 151 ...

  3. POJ-2356 Find a multiple(DFS,抽屉原理)

    Find a multiple Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7133 Accepted: 3122 Speci ...

  4. POJ1426 Find The Multiple (宽搜思想)

    Find The Multiple Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 24768   Accepted: 102 ...

  5. poj1426 Find The Multiple

    Find The Multiple Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 14622   Accepted: 593 ...

  6. POJ1426:Find The Multiple(算是bfs水题吧,投机取巧过的)

    http://poj.org/problem?id=1426 Description Given a positive integer n, write a program to find out a ...

  7. POJ1426 Find The Multiple —— BFS

    题目链接:http://poj.org/problem?id=1426 Find The Multiple Time Limit: 1000MS   Memory Limit: 10000K Tota ...

  8. [POJ]Find The Multiple(DFS)

    题目链接 http://poj.org/problem?id=1426 题意 输入一个数n,输出任意一个 只含0.1且能被n整除的数m.保证n<=200,m最多100位. 题解 DFS/BFS都 ...

  9. POJ1426——Find The Multiple (简单搜索+取余)

    题意: 给一个数n,让你找出一个只有1,0,组成的十进制数,要求是找到的数可以被n整除. 用DFS是搜索 当前位数字 (除最高位固定为1),因为每一位都只有0或1两种选择,换而言之是一个双入口BFS. ...

随机推荐

  1. chrome浏览器canvas画图不显示

    问题产生在学习cabvas给画布画图像的时候发现使用IE edge浏览器可以正常显示图像,而chrome则不行,经百度后知道是因为chrome浏览器会先加载javascript代码,之后才加载图片,这 ...

  2. k8s阅读笔记1-云原生

    前言 阅读书籍地址https://rootsongjc.gitbooks.io/kubernetes-handbook/content/cloud-native/cloud-native-defini ...

  3. 日期格式化:SimpleDateFormat【线程不安全】、FastDateFormat和Joda-Time【后两个都是线程安全】

    SimpleDateFormat是线程不安全的,不能多个线程公用.而FastDateFormat和Joda-Time都是线程安全的,可以放心使用. SimpleDateFormat是JDK提供的,不需 ...

  4. ltp-ddt realtime_cpuload_10p 涉及的cpuloadgen交叉编译及安装

    1.下载源码 https://github.com/ptitiano/cpuloadgen/archive/v0.94.tar.gz 解压 tar -zxvf cpuloadgen-0.94.tar. ...

  5. 【串线篇】Mybatis缓存简介

    缓存:暂时的存储一些数据:加快系统的查询速度... CPU: 主频:4-2.7GHZ 内存:4G-8G    1333MHZ    2166MHZ CPU:一级缓存(4MB):二级缓存 (16MB); ...

  6. ElasticSearch 单台服务器部署多个节点

    转载:https://www.cnblogs.com/wxw16/p/6160186.html 一般情况下单台服务器只会部署一个ElasticSearch node,但是在学习过程中,很多情况下会需要 ...

  7. ubuntu 开启ftp服务

    一. 检查是否已安装 vsftpd vsftpd -v 二. 安装 vsftpd apt-get install vsftpd 三.  检查是否已安装好 vsftpd vsftpd -v system ...

  8. 使用axios上传文件到阿里云对象文件存储服务器oss

    背景 OSS可用于图片.音视频.日志等海量文件的存储.各种终端设备.Web网站程序.移动应用可以直接向OSS写入或读取数据.OSS支持流式写入和文件写入两种方式.使用阿里云oss做文件存储的时候,不可 ...

  9. vue内置组件——transition简单原理图文详解

    基本概念 Vue 在插入.更新或者移除 DOM 时,提供多种不同方式的应用过渡效果 在 CSS 过渡和动画中自动应用 class 可以配合使用第三方 CSS 动画库,如 Animate.css 在过渡 ...

  10. python py文件转换成exe

    1.首先学会了最简单的方法 1)pip install pyinstaller  安装pyinstall 2)pyinstaller  aaaa.py 转换,会在当前目录下建两个文件夹,其中一个文件夹 ...