From e1ddeb4fd42f2fe9b6847df3365d46e485fbda40 Mon Sep 17 00:00:00 2001 From: rl544 <111494264+rl544@users.noreply.github.com> Date: Fri, 16 Dec 2022 20:35:36 +0900 Subject: [PATCH] =?UTF-8?q?uploaded=20at=202022.=2012.=2016.=20=EC=98=A4?= =?UTF-8?q?=ED=9B=84=208:35:35?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- programmers/소수 찾기/solution.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 programmers/소수 찾기/solution.java diff --git a/programmers/소수 찾기/solution.java b/programmers/소수 찾기/solution.java new file mode 100644 index 0000000..2acbc82 --- /dev/null +++ b/programmers/소수 찾기/solution.java @@ -0,0 +1,18 @@ +// [문제 링크]: https://school.programmers.co.kr/learn/courses/30/lessons/12921 + +class Solution { + public int solution(int n) { + int answer = 0; + for(int a = 2; a<=n; a++){ + int t = 0; + for(int b=2; b<=Math.sqrt(a); b++){ + if(a%b==0) { + t = 1; + break; + } + } + if(t == 0) answer+= 1; + } + return answer; + } +} \ No newline at end of file