• poj 1426 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 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'组成。
         如果搜到m则输出,否则搜索m×10和m×10+1直到得出答案

     1 #include <iostream>
     2 #include <stack>
     3 #include <queue>
     4 #include <cstdio>
     5 using namespace std;
     6 #define LL unsigned long long
     7 int n;
     8 bool flag;
     9 void dfs(LL x,int step)
    10 {
    11     if(flag||step==19)//搜索到或者到第19步时返回,因为第20层就超出了unsigned long long范围
    12         return ;
    13     if(x%n==0)
    14     {  //发现输出答案,并标记
    15         printf("%llu
    ",x);
    16         flag=true;
    17         return ;
    18     }
    19     dfs(x*10,step+1);
    20     dfs(x*10+1,step+1);
    21     return ;
    22 }
    23 int main()
    24 {
    25     while(scanf("%d",&n),n)
    26     {
    27         flag=false; //标记是否找到题意之中的m
    28         dfs(1,0); // 从1开始搜索n的倍数
    29     }
    30     return 0;
    31 }
    View Code
    
    
    
     
  • 相关阅读:
    java n!乘阶之和的计算 ,1!+2!+...+20!
    java 进制转换
    jquery 获取元素的绑定事件的处理代码
    java 三维数组取值
    java 计算对数函数
    js 各浏览器不兼容方法 replaceAll 解决
    SourceMap编解码原理
    如何重用浏览器tab打开页面
    npm相关知识
    关于appleScript的一些入门知识
  • 原文地址:https://www.cnblogs.com/cxbky/p/4852227.html
Copyright © 2020-2023  润新知