POJ 1426 Find The Multiple
来源:互联网 发布:淘宝怎么修改实名认证 编辑:程序博客网 时间:2024/05/06 00:49
D - Find The Multiple
Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64uDescription
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
26190
Sample Output
10100100100100100100111111111111111111
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;}
0 0
- poj 1426 Find The Multiple
- Poj 1426 Find The Multiple
- POJ 1426 Find the Multiple
- poj 1426Find The Multiple
- POJ 1426 Find The Multiple
- POJ 1426 Find The Multiple
- POJ 1426 Find The Multiple
- POJ 1426 Find The Multiple
- poj - 1426 - Find The Multiple
- POJ 1426 Find The Multiple
- POJ-1426-Find The Multiple
- POJ 1426 Find The Multiple
- POJ 1426 Find The Multiple
- POJ 1426 Find The Multiple
- POJ 1426 Find The Multiple
- POJ 1426 Find The Multiple
- poj 1426 Find The Multiple
- POJ 1426 Find The Multiple
- QT 设置QTableWidget背景为透明
- mybatis中小于号的用法
- 关于android应用程序签名的一些事儿
- Android版本更新不成功原因分析
- Linux中tar命令详解
- POJ 1426 Find The Multiple
- POSIX多线程程序设计(第1章:概述)
- 计算机网络组网与配置技术—— 读书笔记5、计算机网络常用命令
- 使用 Eclipse 插件提高代码质量,让开发自动化。
- C/C++ 算法 中缀转后缀表达式实现2---实现加减乘除四则算数(整型,包括括号)
- CentOS7.1下生产环境Keepalived+Nginx配置
- Android插件化开发之OpenAtlas插件的安装与卸载、更新与回滚
- 黑马程序员——C语言中的源程序
- 机器学习--KNN分类