코딩테스트
[백준/1271/엄청난 부자2]
개발하는지호
2024. 3. 26. 01:31
https://www.acmicpc.net/problem/1271
1271번: 엄청난 부자2
첫째 줄에는 최백준 조교가 가진 돈 n과 돈을 받으러 온 생명체의 수 m이 주어진다. (1 ≤ m ≤ n ≤ 101000, m과 n은 10진수 정수)
www.acmicpc.net
<<풀이>>
BigInteger에 대해 한 번 더 풀어보고자 찾아서 풀어보았다.
문제 자체는 쉬운데 크기 범위로 인해서 적절한 타입을 선택해야한다.
여기서 nextBigInteger라는 Scanner의 메서드를 알 수 있었따.
또한 remainder라는 나머지를 구하는 메서드도 배울 수 있었다.
import java.math.BigInteger;
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
BigInteger n = in.nextBigInteger();
BigInteger m = in.nextBigInteger();
System.out.println(n.divide(m));
System.out.println(n.remainder(m));
}
}
<<추가 공부>>
BigInteger n = in.nextBigInteger();