2018/12/08 L1-046 整除光棍 Java

练习了BigInteger的使用的方法, 代码如下:

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigInteger;

public class Main {

    public static void main(String[] args) throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));        
        BigInteger bigNum = new BigInteger(String.valueOf(1));
        int index = 1;
        int num = Integer.parseInt(br.readLine());
        BigInteger intToBig = BigInteger.valueOf(num);
        if(num > 0 && num < 1000 && num%2 != 0 && num%5 != 0) {  // 满足条件 1、num为小于1000的正数 2、num为奇数 3、num个位不是5
            while( true) {
                if(bigNum.mod(intToBig).intValue() != 0) {  // 111不能整除输入的数
                    bigNum = bigNum.multiply(BigInteger.valueOf(10));
                    bigNum = bigNum.add(BigInteger.valueOf(1));
                    index++;
                } else {
                    System.out.print(bigNum.divide(intToBig) + " " + index);
                    return;
                }
            }
        } else {
            return;
        }
        

    }

}

 

posted @ 2018-12-08 20:04  HHZZHH  阅读(344)  评论(0编辑  收藏  举报