poj1426

Find The Multiple

Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 27177   Accepted: 11309   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

Dhaka 2002

题解:

题目的意思就是给你一个数n,让你找到一个它的倍数只由1和0组成。(任何一个都可以,Special Judge)

AC代码:(c++)

#include<cstdio>
using namespace std;
int n,flag;
void go(long long p,int k){
    if(flag||k==20) return ;
    if(p%n==0){
        printf("%I64u\n",p);
        flag=1;
    }
    else{
        go(p*10,k+1);
        go(p*10+1,k+1);
    }
}
int main(){
    for(scanf("%d",&n);n;scanf("%d",&n)) flag=0,go(1,1);
    return 0;
}
时间: 2024-11-20 17:57:24

poj1426的相关文章

搜索专题小结及例题:POJ2251&amp;POJ1426&amp;POJ3087&amp;POJ2488

图的遍历也称为搜索,就是从图中某个顶点出发,沿着一些边遍历图中所有的顶点,且每个顶点仅被访问一次,遍历可采取两种不同的方式:深度优先搜索(DFS)和广度优先搜索(BFS). 1.DFS算法思想` 从顶点v出发深度遍历图G的算法 ① 访问v0顶点,置vis[v0]=1,搜索v0未被访问的邻接点w,若存在邻接点w,则dfs(w),直到到达所有邻接点都被访问过的顶点u为止,接着退回一步,看是否还有其他没有被访问的邻接点.如果有,则访问此顶点,进行前述类似的访问,如果没有,就在退回一步进行搜索,重复上述

UVALive2701 UVA1189 POJ1426 ZOJ1530 Find The Multiple

Regionals 2002 >> Asia - Dhaka 问题链接:UVALive2701 UVA1189 POJ1426 ZOJ1530 Find The Multiple. 问题简述:输入若干个正整数n,n=0则结束.对于输入的n,输出正整数m,m是n的倍数并且只包含数字0和1. 问题分析:所求的值不是很大的话,用类型unsigned long long就可以了.开始时,先用1试探,然后是10和11,然后是100.101.110和111,位数逐步增加直到找到能被n整除的数为止. 这个程

poj1426(暴力dfs)

题目链接:https://vjudge.net/problem/POJ-1426 题意:给出n(1<=n<=200),求出全部由01组成的能整除n的正整数. 思路:此题在unsigned long long以内就可以找到满足条件的数,因此限制递归深度为20,然后枚举每一位两种可能即可. AC代码: #include<cstdio> #include<algorithm> using namespace std; int n,cnt,flag,res,ans[105];

POJ1426——BFS——Find The Multiple

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 mo

poj1426 - Find The Multiple [bfs 记录路径]

传送门 转:http://blog.csdn.net/wangjian8006/article/details/7460523 (比较好的记录路径方案) 1 #include<iostream> 2 #include<cstring> 3 #include<cstdlib> 4 #include<cstdio> 5 #include<algorithm> 6 #include<cmath> 7 #include<queue>

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

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

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

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 c

poj1426——Find The Multiple(BFS)

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 mo

poj-1426(转)

大致题意: 给出一个整数n,(1 <= n <= 200).求出任意一个它的倍数m,要求m必须只由十进制的'0'或'1'组成.  BFS+同余模定理没有看懂,看到个DFS写的,先转了,以后再看BFS的. #include <stdio.h> int n,flat; unsigned long long b; void DFS(unsigned long long a,int step) { if(flat||step==19) { return ; } if(a%n==0) { p