POJ 1426 Find The Multiple
2015-08-25 16:48
337 查看
D - Find The Multiple
Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d
& %I64u
SubmitStatusPracticePOJ
1426
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
Sample Output
BFS搜索。
题目大概意思是给一个数n,让你找出一个只有1,0,组成的十进制数,要求是找到的数可以被n整除。不能超过100个数字。输出一个满足的数组即可。
假如n=6;
1余n=1;
10余n=1*10%6=4;
11余n=(1*10+1)%6=5;
100余n=4*10%6=4;
101余n=(4*10+1)%6=5;
110余n=5*10%6=2;
111余n=(5*10+1)%6=3;
可以推知10........01余n=(10.........0余n*10+1)余n;
当然这个搜索的效率貌似不高。438ms.
Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d
& %I64u
SubmitStatusPracticePOJ
1426
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
BFS搜索。
题目大概意思是给一个数n,让你找出一个只有1,0,组成的十进制数,要求是找到的数可以被n整除。不能超过100个数字。输出一个满足的数组即可。
假如n=6;
1余n=1;
10余n=1*10%6=4;
11余n=(1*10+1)%6=5;
100余n=4*10%6=4;
101余n=(4*10+1)%6=5;
110余n=5*10%6=2;
111余n=(5*10+1)%6=3;
可以推知10........01余n=(10.........0余n*10+1)余n;
当然这个搜索的效率貌似不高。438ms.
#include<stdio.h> #include<queue> using namespace std; void bfs(int n) { queue<long long>q; q.push(1); while(!q.empty()) { long long x; x=q.front(); q.pop(); if(x%n==0) { printf("%lld\n",x); return ; } q.push(x*10); q.push(x*10+1); } } int main() { int n; while(scanf("%d",&n)>0&&n) { bfs(n); } return 0; }
相关文章推荐
- 关于android应用程序签名的一些事儿
- Leetcode 58 Length of Last Word 难度:0
- iOS无限循环滚动scrollview
- Scala 深入浅出实战经典 第65讲:Scala中隐式转换内幕揭秘、最佳实践及其在Spark中的应用源码解析
- laravel5 centos6.4下的配置体验
- 缓冲区的C++封装
- QT 设置QTableWidget背景为透明
- Linux expect 特殊字符处理
- Linux学习5_Linux 下hosts文件详解
- AndroidWear 创建Android Wear 项目
- POJ-1012 Joseph-约瑟夫问题好人坏人
- 视图跳转按钮
- nc 通过表头主表主键获取AggVO
- 浅谈从项目型公司到产品型公司的转型
- 高级sql 分组汇总
- actionlib的身世之谜
- Altium_Designer原理图模版制作
- 新版本的jquery checkbox 全选反选代码只能执行一遍,第二次就失败attr与prop区别
- BA--冷源系统原理图解
- easyUI的列名实现简单的树形结构