题目链接:http://poj.org/problem?id=1426

Find The Multiple
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 34218   Accepted: 14337   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


题解:

题目说答案的位数不会超过100,所以以为是:高精度 + 模运算。这样也太丧心病狂了吧!

后来实在想不到其他方法,就看了题解。结果是一道普通的搜索题,答案用long long存就够了(题目不是说位数<=100),感觉被骗了。

再一次受到了启发:面对一些题目(人生也如此)时,如果想到的方法似乎不能解决问题,但除此之外又无其他办法,那就就要放开手脚试一试,不要畏手畏脚。如果想到的唯一方法都搁置不试,那就相当于交白卷了;试一试,或许能出现意想不到的结果。


代码如下:

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <set>
#define ms(a,b) memset((a),(b),sizeof((a)))
using namespace std;
typedef long long LL;
const int INF = 2e9;
const LL LNF = 9e18;
const int MOD = 1e9+;
const int MAXN = +; queue<LL>q;
LL bfs(int n)
{
while(!q.empty()) q.pop();
q.push(); while(!q.empty())
{
LL x = q.front();
q.pop();
if(x%n==)
return x;
q.push(1LL*x*);
q.push(1LL*x*+);
}
} int main()
{
int n;
while(scanf("%d",&n) && n)
{
cout<< bfs(n) <<endl;
}
}

最新文章

  1. php内核分析(三)-全局变量
  2. nginx 模块讲解
  3. ASP.NET 服务器控件的生命周期
  4. mongodb的备份
  5. MySQL编译安装错误:No curses/termcap library found的解决方法
  6. java项目导入IntelliJ IDEA
  7. 图解SQL的inner join、left join、right join、full outer join、union、union all的区别
  8. hdu 1301 Jungle Roads 最小生成树
  9. 【转】C++ 智能指针详解
  10. Node.js学习(10)----文件系统fs
  11. JQuery无法获取动态添加的图片宽度问题解决办法
  12. java开发之基础篇2
  13. 【Demo 0008】Java基础-抽象类
  14. mongodb时间戳转换成格式化时间戳
  15. Apache多端口配置
  16. 201521123065 《Java程序设计》第5周学习总结
  17. Cup(二分)
  18. 文本分类实战(四)—— Bi-LSTM模型
  19. Spring之BeanPostProcessor(后置处理器)介绍
  20. python批量拷贝文件

热门文章

  1. Dynamic Rankings(zoj 2112)
  2. BSGS算法 (小步大步 Baby Step Gaint Step)
  3. Mysql字符集与校对规则
  4. linux基础命令之一
  5. android 布局之LinearLayout(学习一)
  6. 快速掌握RabbitMQ(四)——两种消费模式和QOS的C#实现
  7. P1717 钓鱼 洛谷
  8. List 与 ArrayList 的使用
  9. amplab
  10. dwarf调试信息格式入门