PAT——1017. A除以B

本题要求计算A/B,其中A是不超过1000位的正整数,B是1位正整数。你需要输出商数Q和余数R,使得A = B * Q + R成立。

输入格式:

输入在1行中依次给出A和B,中间以1空格分隔。

输出格式:

在1行中依次输出Q和R,中间以1空格分隔。

输入样例:

123456789050987654321 7

输出样例:

17636684150141093474 3


 1 package com.hone.basical;
 2 import java.math.BigInteger;
 3 import java.util.Scanner;
 4 /**
 5  * 原题目:https://www.patest.cn/contests/pat-b-practise/1016
 6  * @author Xia
 7  * 大数的处理
 8  */
 9 public class basicalLevel1017AdivideB{
10     public static void main(String[] args){
11         Scanner s = new Scanner(System.in);
12         BigInteger a;
13         a = s.nextBigInteger();
14         int b = s.nextInt();
15         System.out.print(a.divide(BigInteger.valueOf(b))+" "+a.mod(BigInteger.valueOf(b)));
16     } 
17 } 

 

posted @ 2017-12-04 19:52  SnailsCoffee  阅读(255)  评论(0编辑  收藏  举报