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)));
        }
    }

}
时间: 2024-10-12 00:16:47

HDOJ 1212 Big Number的相关文章

HDOJ 1266 Reverse Number(数字反向输出题)

Problem Description Welcome to 2006'4 computer college programming contest! Specially, I give my best regards to all freshmen! You are the future of HDU ACM! And now, I must tell you that ACM problems are always not so easy, but, except this one- Ha-

HDOJ 1018 Big Number(大数位数公式)

Problem Description In many applications very large integers numbers are required. Some of these applications are using keys for secure transmission of data, encryption, etc. In this problem you are given a number, you have to determine the number of

HDOJ(HDU) 1562 Guess the number(水题,枚举就行)

Problem Description Happy new year to everybody! Now, I want you to guess a minimum number x betwwn 1000 and 9999 to let (1) x % a = 0; (2) (x+1) % b = 0; (3) (x+2) % c = 0; and a, b, c are integers between 1 and 100. Given a,b,c, tell me what is the

HDOJ 1005 Number Sequence

Problem Description A number sequence is defined as follows: f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7. Given A, B, and n, you are to calculate the value of f(n). Input The input consists of multiple test cases. Each test case co

HDOJ 1391 Number Steps(打表DP)

Problem Description Starting from point (0,0) on a plane, we have written all non-negative integers 0, 1, 2,- as shown in the figure. For example, 1, 2, and 3 has been written at points (1,1), (2,0), and (3, 1) respectively and this pattern has conti

HDOJ(HDU) 2113 Secret Number(遍历数字位数的每个数字)

Problem Description 有一天, KIKI 收到一张奇怪的信, 信上要KIKI 计算出给定数各个位上数字为偶数的和. eg. 5548 结果为12 , 等于 4 + 8 KIKI 很苦恼. 想请你帮忙解决这个问题. Input 输入数据有多组,每组占一行,只有一个数字,保证数字在INT范围内. Output 对于每组输入数据,输出一行,每两组数据之间有一个空行. Sample Input 415326 3262 Sample Output 12 10 简单题. 注意输出格式就行!

java-调webservice 报Maximum Number of Children Elements Exceeded错误,大神们怎么解决?

问题描述 调webservice 报Maximum Number of Children Elements Exceeded错误,大神们怎么解决? org.apache.cxf.interceptor.Fault: Unmarshalling Error: Maximum Number of Children Elements Exceeded at org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java

最大匹配-HDOJ 2458 Kindergarten

HDOJ 2458 Kindergarten Description In a kindergarten, there are a lot of kids. All girls of the kids know each other and all boys also know each other. In addition to that, some girls and boys know each other. Now the teachers want to pick some kids 

最大匹配-HDOJ 1068

HDOJ 1068 Girls and Boys . Problem Description the second year of the university somebody started a study on the romantic relations between the students. The relation "romantically involved" is defined between one girl and one boy. For the study