728x90
소수 만들기
-
프로그래머스 (Level 1) - 소수 만들기Coding Test/Coding Test 문제 풀이 2021. 12. 26. 16:16
문제 설명 코딩테스트 연습 - 소수 만들기 주어진 숫자 중 3개의 수를 더했을 때 소수가 되는 경우의 개수를 구하려고 합니다. 숫자들이 들어있는 배열 nums가 매개변수로 주어질 때, nums에 있는 숫자들 중 서로 다른 3개를 골라 더했을 때 programmers.co.kr 풀이 주어진 정수형 배열 nums에서 임의의 3개의 수를 더했을 때 소수가 되는 경우의 개수를 구하는 문제이다. 우선, 정수형 배열 nums에서 완전 탐색 기법을 사용해서 3개의 숫자로 구성할 수 있는 모든 조합을 탐색하였다. 3개의 숫자 조합을 탐색할 때마다 3개 숫자의 합을 구하고, 구한 숫자가 소수인지 아닌지 판별 함으로써 문제를 해결하였다. 전체 소스코드 import java.io.*; import java.util.*; p..