首页 > 专题系列 > Java解POJ > POJ 1426 Find The Multiple [解题报告] Java
2013
11-09

POJ 1426 Find The Multiple [解题报告] Java

Find The Multiple

问题描述 :

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.

样例输入:

2
6
19
0

样例输出:

10
100100100100100100
111111111111111111

解题代码:

//* @author  [email protected]
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
public class Main {
    public static void main(String[] args) throws IOException {
        BigInteger a;
        BigInteger b;
        BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));
        long c=0,d=0;
        long n=0;
        while((n=Long.parseLong(stdin.readLine()))!=0){
        //for(n=1;n<=200;n++)   {
        b=new BigInteger(1+"");
        d=1;
            while(true){
                c=Long.parseLong(Long.toBinaryString(d));
                //a=new BigInteger(b.toString(2));
                //if(a.mod(new BigInteger(n+"")).toString().equals("0"))break;
                if(c%n==0) break;
                //b=b.add(new BigInteger("1"));
                d++;
            }
            System.out.println(Long.toBinaryString(d));
        }
    }
}

  1. “再把所有不和该节点相邻的节点着相同的颜色”,程序中没有进行不和该节点相邻的其他节点是否相邻进行判断。再说求出来的也不一样是颜色数最少的