1017 A除以B (20分)
本题要求计算 A/B,其中 A 是不超过 1000 位的正整数,B 是 1 位正整数。你需要输出商数 Q 和余数 R,使得 A=B×Q+R 成立。
输入格式:
输入在一行中依次给出 A 和 B,中间以 1 空格分隔。
输出格式:
在一行中输出 PA+PB 的值。
输入样例:
123456789050987654321 7
输出样例:
17636684150141093474 3
这个也很简单啦,没有什么大数是BigInteger不能解决的,代码如下:
import java.math.BigInteger;
import java.util.Scanner;
public class Pro_1017 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String str = in.nextLine();
in.close();
String str1 = str.split(" ")[0];
String str2 = str.split(" ")[1];
BigInteger a = new BigInteger(str1);
BigInteger b = new BigInteger(str2);
BigInteger q = a.divide(b);
BigInteger r = a.add(b.multiply(q).negate());
System.out.println(q+" "+r);
}
}