Find the Multiple
来源:互联网 发布:蓝月羽毛升级数据 编辑:程序博客网 时间:2024/06/06 20:19
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.
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.
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.
26190这道题的大意是这样的:找到一个由0和1组成的十进制数字,使得这个数是所输入的数的倍数。
这道题呢其实是在吓人,它说是一百位,但实际上开个long long 就可以过了,看的就是你敢不敢去是。
知道题就是一个深搜的题,因为这个是0 1 串,所以我们从1开始搜,往10*k和10*k+1方向搜,保证能搜到全部 01 串,但是我们也要有个边界条件,那就是到了20位或者已经搜到了符合条件的数,那么我们就跳出。
#include<iostream> using namespace std;int b;unsigned long long ans;bool f;void search(unsigned long long a,int s){if (f) return;if (s >= 19) return;if(a%b==0){ans = a;f = 1;return;}else {for(int i=0;i<2;i++){//两个方向乘10加1或不加1search(a*10+i,s+1);}}} int main(){while(cin>>b&&b!=0){search(1,0);cout<<ans<<endl;f=0;ans=0;}
阅读全文
1 0
- POJ1426 Find The Multiple
- poj1426 Find The Multiple
- G - Find The Multiple
- poj1426 - Find The Multiple
- POJ1426 Find The Multiple
- POJ1426-Find The Multiple
- Find The Multiple
- poj find the multiple
- poj1426 Find The Multiple
- poj1426-Find The Multiple
- POJ1426 Find the multiple
- POJ1426-Find The Multiple
- POJ1426 Find The Multiple
- zoj1530 Find The Multiple
- Find The Multiple
- Find The Multiple
- poj1426 Find The Multiple
- Find The Multiple poj1426
- 十七、服务网关-Zuul 的使用
- bootsrap
- 404页面与500页面
- linux设备驱动模型架构分析(二)——LDDM的底层实现kobject
- bootstrap
- Find the Multiple
- hdu--6047--Maximum Sequence
- MyEclipse自动生成注释配置
- 十八、服务网关-Zuul 如何对过滤器进行自定义
- 练习(四)
- CSU-ACM2017暑期训练3-递推与递归 J
- CSU-ACM2017暑期训练3-递推与递归 H
- Nexus私服的使用
- Python for 循环语句