Find The Multiple(POJ--1426
来源:互联网 发布:假钞在淘宝中的暗语 编辑:程序博客网 时间:2024/06/05 15:08
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.
题意:多组输入,每组输入一个n,求能整除n且只能由0和1组成的数,如果有多种情况只要输出一种即可。
Sample Input
26190
Sample Output
10100100100100100100111111111111111111
#include <cstdio>#include <iostream>#include <cstring>#include <algorithm>#include <cmath>#include <queue>#define MAX 100005#define mod 99991using namespace std;int n;void BFS(){ queue <long long>q; //求得的数可能超过整型,所以用long long型的队列 q.push(1); //求得的数的最高位肯定是1而不会是0 while(!q.empty()) { long long int x; x=q.front(); q.pop(); if(x%n==0) { printf("%lld\n",x); return ; } q.push(x*10); //要么添0 q.push(x*10+1); //要么添1 }}int main(){ //freopen("lalala.text","r",stdin); while(~scanf("%d",&n)) { if(!n) break; BFS(); } return 0;}<strong></strong>
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
- C++集合操作之集合对称差集:std::set_symmetric_difference
- PHP学习总结(四)
- uboot学习笔记
- 整形数组合并_用 set
- nyoj38 布线问题
- Find The Multiple(POJ--1426
- linux安装vmware tools 找不到kernel路径
- Vijos1909 寻找道路
- js获取各种浏览器宽度
- MYSQL主从表插入,使用存储过程
- postgresql cluster table
- 霸王别姬与蓝宇
- Netmask, 子网与 CIDR (Classless Interdomain Routing)
- Majority Element