LightOJ 1214 Large Division

来源:互联网 发布:顺丰软件 编辑:程序博客网 时间:2024/05/20 22:36

可以用JAVA BigInteger 但是要注意 BigInteger 的类方法中取余有两个方法一个是 mod, 一个是remainder 对于方法mod当余数是负数时会抛出异常, 而remainder 就会正常得出余数

import java.math.*;import java.util.*;import java.io.*;public class Main{    public static void main(String args[])    {      Scanner cin = new Scanner( new BufferedInputStream( System.in ) );      int t, i;      t = cin.nextInt();      for(i = 1; i <= t; i++)      {         BigInteger a = cin.nextBigInteger();         BigInteger b = cin.nextBigInteger();         BigInteger c = a.remainder(b);         BigInteger x = BigInteger.valueOf(0);         if(c.compareTo(x) == 0)           System.out.println("Case "+i+": "+"divisible");         else             System.out.println("Case "+i+": "+"not divisible");      }    }}
0 0