浏览器标题切换
浏览器标题切换end

POJ1426-Find The Multiple-bfs

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

题意:找到只由0或1组成的小于100位的数能够整除题目给出的数据
复制代码
 1 #include<iostream>
 2 #include<queue>
 3 using namespace std;
 4 
 5 int n;
 6 void bfs(int x)
 7 {
 8 
 9     queue<long long>Q;
10     long long p=1;
11     Q.push(p);
12     while(!Q.empty())
13     {
14         p=Q.front();
15         Q.pop();
16         if(p%n==0)
17         {
18             cout<<p<<endl;
19             break;
20         }
21         Q.push(p*10);
22         Q.push(p*10+1);
23     }
24     return ;
25 }
26 
27 
28 
29 int main()
30 {
31     std::ios::sync_with_stdio(false);
32     while(cin>>n)
33     {
34         if(n==0)
35             break;
36         else
37         {
38             bfs(n);
39         }
40     }
41     return 0;
42 }
View Code
复制代码

 

posted @   抓水母的派大星  阅读(205)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· DeepSeek 开源周回顾「GitHub 热点速览」
点击右上角即可分享
微信分享提示