POJ 1426 Find The Multiple【dfs】


Find The Multiple

Time Limit: 1000MS

Memory Limit: 10000K

Total Submissions: 22877

Accepted: 9431

Special Judge

Description

Given a positiveinteger n, write a program to find out a nonzero multiple m of n whose decimalrepresentation contains only the digits 0 and 1. You may assume that n is notgreater than 200 and there is a corresponding m containing no more than 100decimal digits.

Input

The input file maycontain 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 ofn in the input print a line containing the corresponding value of m. Thedecimal representation of m must not contain more than 100 digits. If there aremultiple 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),求任意一个N的倍数M*N【这个是我设】,使得数的十进制位每位都是由0或1组成。任意输出一组解就行。题目保证有解。

思路:

__int64可以装下。那么最多到达20个十进制位,那么就可以直接dfs水过了=_=

实现代码:

 

#include <queue>
#include <cmath>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define FIN             freopen("input.txt","r",stdin)
#define FOUT            freopen("output.txt","w",stdout)
typedef long long LL;
int N;
bool suc;
void dfs(LL M, int bit) {
    if(bit >= 20 || suc) return;
    if(M % N == 0) {
        suc = true;
        printf("%I64d\n", M);
        return;
    }
    dfs(M * 10, bit + 1);
    dfs(M * 10 + 1, bit + 1);
}
int main()
{
//    FIN;
    while(~scanf("%d", &N) && N) {
        suc = false;
        dfs(1, 1);
    }
    return 0;
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值