[BaekJoon] 1271번 - 엄청난 부자2 [Java]
[BaekJoon] 1271번 - 엄청난 부자2 [Java]
1. 문제 풀이
두 정수 $n$, $m$ 에 대해 몫과 나머지를 구하는 문제로 수의 범위가 매우 크다. 큰 수를 다룰 수 있는 도구나 라이브러리를 활용하면 간단하게 해결할 수 있다.
2. 코드
1. 풀이 [Java]
큰 정수의 연산을 처리할 수 있는 BigInteger 클래스를 활용했다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import java.io.*;
import java.math.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
BigInteger n = new BigInteger(st.nextToken());
BigInteger m = new BigInteger(st.nextToken());
System.out.println(n.divide(m));
System.out.println(n.mod(m));
}
}
This post is licensed under CC BY 4.0 by the author.