๐ก ๋ฌธ์์ด ํํ๋ก ์ด๋ฃจ์ด์ ธ ์์ด ์ซ์์ ๋ฒ์๊ฐ ๋ฌดํํจ
Type | ๋ฒ์ |
int | -2,147,483,648 ~ 2,147,483,647 |
long | -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 |
BigInteger ๊ณ์ฐ
- ๋ฌธ์์ด์ด๋ฏ๋ก ์ฌ์น์ฐ์ฐ ๋ถ๊ฐ → ๋ด๋ถ ๋ฉ์๋ ์ฌ์ฉ
BigInteger bigNumber1 = new BigInteger("100000");
BigInteger bigNumber2 = new BigInteger("10000");
System.out.println("๋ง์
(+) :" +bigNumber1.add(bigNumber2));
System.out.println("๋บ์
(-) :" +bigNumber1.subtract(bigNumber2));
System.out.println("๊ณฑ์
(*) :" +bigNumber1.multiply(bigNumber2));
System.out.println("๋๋์
(/) :" +bigNumber1.divide(bigNumber2));
System.out.println("๋๋จธ์ง(%) :" +bigNumber1.remainder(bigNumber2));
BigInteger ํ ๋ณํ
BigInteger bigNumber = BigInteger.valueOf(100000); //int -> BigIntger
int int_bigNum = bigNumber.intValue(); //BigIntger -> int
long long_bigNum = bigNumber.longValue(); //BigIntger -> long
float float_bigNum = bigNumber.floatValue(); //BigIntger -> float
double double_bigNum = bigNumber.doubleValue(); //BigIntger -> double
String String_bigNum = bigNumber.toString(); //BigIntger -> String
BigIntger ๋ ์ ๋น๊ต
BigInteger bigNumber1 = new BigInteger("100000");
BigInteger bigNumber2 = new BigInteger("1000000");
//๋ ์ ๋น๊ต compareTo ๋ง์ผ๋ฉด 0 ํ๋ฆฌ๋ฉด -1
int compare = bigNumber1.compareTo(bigNumber2);
System.out.println(compare);
์์ ๊ตฌํ๊ธฐ
import java.io.*;
import java.math.BigInteger;
public class num4134 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
for(int i=0; i<n; i++) {
BigInteger num = new BigInteger(String.valueOf(Long.parseLong(br.readLine())));
if(num.isProbablePrime(10)) { // ํ์ฌ ๊ฐ์ด ์์์ธ์ง ์๋์ง ํ๋จํ๋ ๋ฉ์๋
System.out.println(num);
} else {
System.out.println(num.nextProbablePrime()); // ๋ค์ ์์ ๊ฐ์ ๋ฐํํด์ฃผ๋ ๋ฉ์๋
}
}
}
}
'Programming Language > JAVA' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[JAVA] ์๋ฐ๋ (0) | 2023.10.19 |
---|---|
[JAVA] ์ง๋ฒ ๋ณํ (0) | 2023.10.13 |
[JAVA] List & Set &Map (0) | 2023.08.15 |
[JAVA] Call By Value์ Call By Reference (0) | 2023.08.15 |
[JAVA] ์ง์ญ ๋ณ์ & ์ ์ญ ๋ณ์ & static(์ ์ ) ๋ณ์ (0) | 2023.08.15 |