POJ - 1426 Find The Multiple (暴力搜索)

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
#include <cstdio>
#include <iostream>
#include <queue>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;

typedef unsigned long long ll;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
ll n,ans;

void bfs(ll x)
{
    queue<ll>q;
    q.push(x);
    while(q.size())
    {
        ll tmp=q.front();
        q.pop();
        if(tmp%n==0)
        {
            ans=tmp;
            return ;
        }
        ll xx=tmp*10;
        q.push(xx);
        if(xx%n==0)
        {
            ans=xx;
            return ;
        }
        xx=tmp*10+1;
        q.push(xx);
        if(xx%n==0)
        {
            ans=xx;
            return ;
        }
    }
}
int main()
{
    while(~scanf("%lld",&n)&&n)
    {
        bfs(1);
        cout<<ans<<'\n';
    }
    return 0;
}

 

全部评论

相关推荐

xtu大迫杰:偶遇校友,祝校友offer打牌
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
正在热议
更多
# 春招至今,你的战绩如何? #
5015次浏览 47人参与
# 你的实习产出是真实的还是包装的? #
1103次浏览 27人参与
# MiniMax求职进展汇总 #
22892次浏览 293人参与
# 军工所铁饭碗 vs 互联网高薪资,你会选谁 #
6907次浏览 37人参与
# 简历第一个项目做什么 #
31251次浏览 312人参与
# 当下环境,你会继续卷互联网,还是看其他行业机会 #
186349次浏览 1115人参与
# 米连集团26产品管培生项目 #
4130次浏览 198人参与
# 面试紧张时你会有什么表现? #
30371次浏览 188人参与
# 简历中的项目经历要怎么写? #
309379次浏览 4152人参与
# 网易游戏笔试 #
6304次浏览 83人参与
# 职能管理面试记录 #
10687次浏览 59人参与
# 把自己当AI,现在最消耗你token的问题是什么? #
6850次浏览 154人参与
# 从哪些方向判断这个offer值不值得去? #
56698次浏览 357人参与
# 腾讯音乐求职进展汇总 #
160394次浏览 1105人参与
# 小红书求职进展汇总 #
226845次浏览 1356人参与
# AI时代,哪些岗位最容易被淘汰 #
62406次浏览 728人参与
# 你怎么看待AI面试 #
179273次浏览 1164人参与
# 正在春招的你,也参与了去年秋招吗? #
362529次浏览 2631人参与
# 你的房租占工资的比例是多少? #
92123次浏览 896人参与
# 机械求职避坑tips #
94396次浏览 567人参与
# 校招笔试 #
466318次浏览 2950人参与
# 面试官最爱问的 AI 问题是...... #
27111次浏览 834人参与
牛客网
牛客网在线编程
牛客网题解
牛客企业服务