HDOJ 1212 Big Number

简介: HDOJ 1212 Big Number

Problem Description

As we know, Big Number is always troublesome. But it’s really important in our ACM. And today, your task is to write a program to calculate A mod B.


To make the problem easier, I promise that B will be smaller than 100000.


Is it too hard? No, I work it out in 10 minutes, and my program contains less than 25 lines.


Input

The input contains several test cases. Each test case consists of two positive integers A and B. The length of A will not exceed 1000, and B will be smaller than 100000. Process to the end of file.


Output

For each test case, you have to ouput the result of A mod B.


Sample Input

2 3

12 7

152455856554521 3250


Sample Output

2

5

1521


public BigDecimal remainder(BigDecimal divisor)返回其值为 (this % divisor) 的 BigDecimal。

余数由 this.subtract(this.divideToIntegralValue(divisor).multiply(divisor)) 给出。注意,这不是模操作(结果可以为负)。

参数:

divisor - 此 BigDecimal 要除以的值。

返回:

this % divisor。

import java.math.BigDecimal;
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            BigDecimal a = sc.nextBigDecimal();
            int b = sc.nextInt();
            System.out.println(a.remainder(new BigDecimal(b)));
        }
    }
}
目录
相关文章
HDOJ(HDU) 2113 Secret Number(遍历数字位数的每个数字)
HDOJ(HDU) 2113 Secret Number(遍历数字位数的每个数字)
92 0
HDOJ(HDU) 1562 Guess the number(水题,枚举就行)
HDOJ(HDU) 1562 Guess the number(水题,枚举就行)
98 0
HDOJ 1391 Number Steps(打表DP)
HDOJ 1391 Number Steps(打表DP)
102 0
HDOJ 1391 Number Steps(打表DP)
HDOJ 1266 Reverse Number(数字反向输出题)
HDOJ 1266 Reverse Number(数字反向输出题)
90 0
|
Java
HDOJ 1018 Big Number(大数位数公式)
HDOJ 1018 Big Number(大数位数公式)
84 0
HDOJ 1005 Number Sequence
HDOJ 1005 Number Sequence
80 0
|
6月前
|
算法
Leetcode 313. Super Ugly Number
题目翻译成中文是『超级丑数』,啥叫丑数?丑数就是素因子只有2,3,5的数,7 14 21不是丑数,因为他们都有7这个素数。 这里的超级丑数只是对丑数的一个扩展,超级丑数的素因子不再仅限于2 3 5,而是由题目给定一个素数数组。与朴素丑数算法相比,只是将素因子变了而已,解法还是和朴素丑数一致的。
65 1
|
4天前
|
存储 算法
【LeetCode力扣】单调栈解决Next Greater Number(下一个更大值)问题
【LeetCode力扣】单调栈解决Next Greater Number(下一个更大值)问题
5 0
|
6月前
|
存储
Leetcode Single Number II (面试题推荐)
给你一个整数数组,每个元素出现了三次,但只有一个元素出现了一次,让你找出这个数,要求线性的时间复杂度,不使用额外空间。
22 0