728x90
🧑💻
백준의 2061번 좋은 암호 문제이다.
package variable.backzun.week03.day01;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
public class 좋은_암호_2061_3번 {
public static void main(String[] args) throws IOException {
/*
BigInteger...
메모리 208248 KB, 시간 528 ms
*/
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] input = br.readLine().split(" ");
BigInteger K = new BigInteger(input[0]); // 10^100 을 담기 위한 BigInteger 클래스로 객체 생성
int L = Integer.parseInt(input[1]);
for(int i = 2; i < L; i++) {
BigInteger num = BigInteger.valueOf(i); // num을 BigInteger 타입으로 변환
if(K.mod(num).equals(BigInteger.ZERO)) { // K % num이 0이면 BAD 출력
System.out.println("BAD " + i);
return;
}
}
System.out.println("GOOD");
}
}
728x90
'알고리즘' 카테고리의 다른 글
[Java] 백준 10419번: 지각 (0) | 2024.06.12 |
---|---|
[Java] 백준 1440번: 타임머신 (0) | 2024.06.12 |
[Java] 백준 2798번: 블랙잭 (0) | 2024.06.12 |
[Java] 백준 13975번: 파일 합치기 (0) | 2024.06.11 |
[Java] 백준 1691번: 숨바꼭질 (0) | 2024.06.11 |