์ ์ฒด ๊ธ
-
[Python] ์๋ผํ ์คํ ๋ค์ค์ ์ฒด (Sieve of Eratosthenes)Algorithm/Basic 2021. 4. 4. 22:00
1. ์ ์ - 2๋ถํฐ ์์ํ์ฌ, ์์์ธ ๊ฒฝ์ฐ ๊ฐ์ ์ถ๋ ฅํ๊ณ , ํด๋น ์์์ ๋ชจ๋ ๋ฐฐ์๋ค์ ์๊ฑฐํด ๋๊ฐ๋ ๋ฐฉ๋ฒ 2. ๋ฐฉ๋ฒ - 2 -> ์์, N๋ณด๋ค ์์ ๋ชจ๋ 2์ ๋ฐฐ์ ์ ๊ฑฐ - 3 -> ์์, N๋ณด๋ค ์์ ๋ชจ๋ 3์ ๋ฐฐ์ ์ ๊ฑฐ - .... - k -> ์์, N๋ณด๋ค ์์ ๋ชจ๋ k์ ๋ฐฐ์ ์ ๊ฑฐ ์๋ฅผ๋ค์ด, 20๊น์ง์ ์์ ๊ตฌํ๊ธฐ๋ฅผ ํ๋ค๋ฉด, 2์ ๋ฐฐ์๋ถํฐ 20๊น์ง์ ๋ฐฐ์๋ฅผ ์ง์์ฃผ๋ ๋ฐฉ์์ด๋ค. import time def isPrime(v): i = 2 while i*i = 2: primeList = list..
-
์ผ์ฑSDS ์ฝ๋ฉ์บ ํผ์ค ๋ด์ฌ๋จ ๋ฉด์ ํ๊ธฐetc 2021. 4. 3. 12:57
๋น๋ก ๊ฒฐ๊ณผ์ ์ผ๋ก ๋จ์ด์ก์ง๋ง, ๋ค์ ๋ฉด์ ์ ์ค๋นํ์๋ ๋ถ๋ค๊ป ๋์์ด ๋ ๊น ์ถ์ด ๋ธ๋ก๊ทธ์ ์ฌ๋ ค์ผ ๊ฒ ๋ค๊ณ ์๊ฐํ๋ค. ๋ญ๊ฐ ๋์ธํ๋์ผ๋ก ์์์๋ฅผ ์ฐ๊ธฐ๋ ์ข์ ๊ฒ๊ฐ๊ณ , ์ด๋ฐ ๋ด์ฌ ๊ฒฝํ์ ํ๋ ๊ฒ ๋ ์ข์ ๊ฒ๊ฐ์ ์ง์ํ๊ฒ ๋์๋ค. ์ค๋๋ง์ ๋ณธ ๋ฉด์ ์ด๋ผ ๋ ๋จ๊ธฐ๋ ๋จ๊ณ , ๋ค๋ฅธ ๋ฉด์ ์ ๋ถ๋ค์ด ๋๋ฌด ๋ง์์ ์ํ์ ์ ๋๋๋ค. ๋ ์ทจ์ ํ ์์๊ฒ ์ง .. ใ ์ผ๋จ ๋ฉด์ ์ ์๊ตญ์ธ๋งํผ ์ค์ผ๋ก ์งํ๋์๊ณ , ๋๊ธฐ์ค์ ๋ค์ด๊ฐ์์ผ๋ฉด 2(๋ฉด์ ๊ด):4(์ง์์) ํ์์ผ๋ก ์ํ์์ค๋ก ๋ฐ๋ก ๋ฐฉ์ด ๋ง๋ค์ด์ ธ ๋ฉด์ ์ด ์งํ๋์๋ค ๋ฉด์ ์ ๋ถ๋ค์ด ๋๊ฒ ์์ผ๋ฉด์ ๋ง์ํ์ ์ ๊ธด์ฅ๋๋ ๋ถ์๊ธฐ์๋ ๊ด์ฐฎ์๋ค! ์ผ๋จ ์ง๋ฌธ์ 1. ์๊ธฐ์๊ฐ์ ์ง์๋๊ธฐ 2. ์ด๋ฑํ๊ต 4ํ๋ ์๊ฒ ์๊ณ ๋ฆฌ์ฆ์ด๋ ์ด๋ป๊ฒ ์ค๋ช ํ ๊ฒ์ธ์ง, ์ ์๊ฒ ์ค๋ช ํด์ฃผ์ธ์ 3. ์์ ์ ์ ๋ด์ฌ๋จ์ ๋ฝ์์ผํ๋ ์ง,..
-
E: Unable to locate package openjdk-8-jdk ํด๊ฒฐ์ฝ์ง๋ชจ์/์๋ฌํด๊ฒฐ 2021. 3. 30. 16:24
ubuntu ํ๊ฒฝ์์ java๋ฅผ ์ค์นํ๋ ค๊ณ ํ๋ ์ฒ์ ๋ง๋๋ ์๋ฌ๋ ,, ๊ณ์ํด์ ์ฐพ์๋ณด๋ ์์น ๋๋ฌธ์ธ๊ฑธ ์๊ฒ๋์๋ค๐ญ ๋ง์ ์ฌ๋๋ค์๊ฒ ๋์์ด ๋๊ธธ ๋ฐ๋ผ๋ฉฐ ์ฌ๋ ค๋ด ๋๋ค cd /usr/local/bin /usr/local/bin ์ผ๋ก ๋ค์ด๊ฐ ํ, java -version ์ ์ณค์ ๋, java ๋ฒ์ ์ด ์๋์จ๋ค๋ฉด java๊ฐ ๊น๋ฆฌ์ง ์์๋ค๋ ๊ฒ์ด๋ฏ๋ก ์ค์น๋ฅผ ์งํ ํ ์ ์๋ค. sudo apt-get update ๋ชจ๋ ๋ฆฌํฌ์งํ ๋ฆฌ ๋ฐ PPA์ ๋ํ ํจํค์ง ๋ชฉ๋ก์ ๊ฐ์ ธ ์์ ์ต์ ์ํ์ธ์ง ํ์ธํ๋ ๋ช ๋ น์ด๋ฅผ ์คํ ์ํจ ํ, sudo apt-get install openjdk-8-jdk java๋ฅผ ์ค์นํ๋ฉด ์ ์์ ์ผ๋ก ์ค์น๋๋ ๊ฒ์ ๋ณผ ์ ์๋ค. ์ฑ๊ณต์ ์ผ๋ก ์ค์น ํ, ์๋ ๋ช ๋ น์ด๋ฅผ ์ณ๋ดค์ ๋, ๋ฒ์ ์ด ์ ๋๋ก ๋์จ๋ค๋ฉด ์ค์น ..
-
02. ์ํComputer Science/Data Structure 2021. 3. 24. 01:25
- ํ์ต๋ชฉํ ์ํ์ ๊ฐ๋ ์ ์ดํดํ๋ค ์ํ ์๊ณ ๋ฆฌ์ฆ์ ๊ตฌ์กฐ๋ฅผ ์ดํดํ๋ค ์ํ ํธ์ถ ์ ์ฃผ์์ฌํญ์ ์ดํดํ๋ค ์ํ ํธ์ถ ์์ฉ๋ ฅ์ ๋ฐฐ์ํ๋ค 2.1 ์ํ์ ์๊ฐ ์ํ? - ์ด๋ค ์๊ณ ๋ฆฌ์ฆ์ด๋ ํจ์๊ฐ ์๊ธฐ ์์ ์ ํธ์ถํ์ฌ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๋ ๊ธฐ๋ฒ ์ํ ์๊ณ ๋ฆฌ์ฆ์ ๊ตฌ์กฐ - ์ํ ํธ์ถ ํ๋ ๋ถ๋ถ - ์ํ ํธ์ถ์ ๋ฉ์ถ๋ ๋ถ๋ถ ์ ํฌํจํ๋ค. ๋ง์ผ, ์ํ ํธ์ถ์ ๋ฉ์ถ๋ ๋ถ๋ถ์ด ์๋ค๋ฉด, ๋ฌดํ์ ํธ์ถํ๊ฒ ๋์ด ์๋ฒ๊ฐ ๋ค์ด๋ ์ ์์ผ๋ฏ๋ก ์ฃผ์ํ์ฌ์ผํ๋ค. ์ํ๊ณผ ๋ฐ๋ณต ์ํ recursion: ์ํ ํธ์ถ์ ์ด์ฉ - ์ํ์ ์ธ ๋ฌธ์ ์์ ์ ๋ฆฌํ๋ค. - ํจ์ ํธ์ถ์ ์ค๋ฒํค๋๊ฐ ์๋ค. -> ์ํ ํธ์ถ ์์๋ ํธ์ถ์ด ์ผ์ด๋ ๋๋ง๋ค ํธ์ถํ๋ ํจ์์ ์ํ๋ฅผ ๊ธฐ์ตํด์ผํ๊ธฐ ๋๋ฌธ์ ์ฌ๋ถ์ ๊ธฐ์ต์ฅ์๊ฐ ํ์ํ๋ค. -> ๋นํจ์จ์ ์ธ ๊ฒฝ์ฐ๊ฐ ๋ง์ ๋ฐ๋ณต iteratio..
-
01. ์๋ฃ๊ตฌ์กฐ์ ์๊ณ ๋ฆฌ์ฆComputer Science/Data Structure 2021. 3. 21. 14:02
- ํ์ต๋ชฉํ ์๋ฃ๊ตฌ์กฐ์ ์๊ณ ๋ฆฌ์ฆ์ ๊ฐ๋ ์ ์ดํดํ๋ค ์ถ์ ์๋ฃํ ๋์ ์ ํ์๋ฅผ ์ดํดํ๋ค ์๊ฐ ๋ณต์ก๋์ ๊ฐ๋ ์ ์ดํดํ๋ค ๋น ์ค ํ๊ธฐ๋ฒ์ ์ํ ์๊ณ ๋ฆฌ์ฆ ๋ถ์ ๊ธฐ๋ฒ์ ์ดํดํ๋ค ์๋ฃ๊ตฌ์กฐ ํ๊ธฐ๋ฒ์ ์ดํดํ๋ค 1.1 ์๋ฃ๊ตฌ์กฐ์ ์๊ณ ๋ฆฌ์ฆ ์๋ฃ๊ตฌ์กฐ๋? - ์ฌ๋๋ค์ด ์ฌ๋ฌผ์ ์ ๋ฆฌํ์ฌ ์ ์ฅํ๋ ๊ฒ๊ณผ ๋ง์ฐฌ๊ฐ์ง๋ก ํ๋ก๊ทธ๋จ์์๋ ์๋ฃ๋ค์ ์ ๋ฆฌํ์ฌ ๋ณด๊ดํ๋ ์ฌ๋ฌ ๊ฐ์ง ๊ตฌ์กฐ๋ค์ด ์๋ค. ์ด๋ฌํ ๊ตฌ์กฐ๋ค์ ์๋ฃ๊ตฌ์กฐ๋ผ ํ๋ค. - ์๋ฅผ ๋ค๋ฉด, ํด์ผํ ์ผ๋ค์ ์ค์๋์ ๋ฐ๋ฅธ ๋ด์ฉ๋ค์ ์ปดํจํฐ๊ฐ ์ดํดํ๋ ค๋ฉด ์์ฐจ์ ์ผ๋ก ์งํํ๋ List๋ฅผ ์ฌ์ฉํด์ผํ๋ค. ์ผ์์ํ ์๋ฃ๊ตฌ์กฐ ๊ทธ๋ฆ, ์ฐํ ์คํ ๋งํธ ๊ณ์ฐ๋์ ์ค ํ ๋ฒํท ๋ฆฌ์คํธ ๋ฆฌ์คํธ ์์ด ์ฌ์ ์ฌ์ ์ง๋ ๊ทธ๋ํ ์ปดํจํฐ์ ๋๋ ํ ๋ฆฌ ๊ตฌ์กฐ ํธ๋ฆฌ ์๊ณ ๋ฆฌ์ฆ์ด๋? - ์ปดํจํฐ๋ก ๋ฌธ์ ๋ฅผ ํ๊ธฐ ์ํ ๋จ๊ณ์ ์ธ ์ ์ฐจ - ํน์ ํ ์ผ..
-
[Python] ์ ํด๋ฆฌ๋ ํธ์ ๋ฒ(Euclidean Algorithm)Algorithm/Basic 2021. 3. 19. 18:46
1. ์ ์ - ๋ ์์ ์ต๋๊ณต์ฝ์๋ฅผ ๊ตฌํ๋ ์๊ณ ๋ฆฌ์ฆ 2. ๋ฐฉ๋ฒ - 2๊ฐ์ ์์ฐ์ a, b(a > b) ์ ๋ํด์ a๋ฅผ b๋ก ๋๋ ๋๋จธ์ง๋ฅผ r์ด๋ผ ํ๋ฉด, a์ b์ ์ต๋ ๊ณต์ฝ์๋ b์ r์ ์ต๋๊ณต์ฝ์์ ๊ฐ์ -> ์ด ์ฑ์ง์ ๋ฐ๋ผ, b๋ฅผ r๋ก ๋๋ ๋๋จธ์ง r'๋ฅผ ๊ตฌํ๊ณ , ๋ค์ r์ r'๋ก ๋๋ ๋๋จธ์ง๋ฅผ ๊ตฌํ๋ ๊ณผ์ ์ ๋ฐ๋ณตํ์ฌ ๋๋จธ์ง๊ฐ 0์ด ๋์์ ๋ ๋๋๋ ์๊ฐ a์ b์ ์ต๋๊ณต์ฝ์๊ฐ ๋๋ค. 3. ๋น๊ต ์ ํด๋ฆฌ๋ ํธ์ ๋ฒ์ด ์๋ ๋ค๋ฅธ ๋ฐฉ๋ฒ์ผ๋ก ์ฝ๋๋ฅผ ์์ฑํ ํ, ์๊ฐ์ ๋น๊ตํด๋ณด์์ต๋๋ค. 2์ด ๊ฐ๋ ์ฐจ์ด๊ฐ ๋๋ค. ๊ฒฐ๋ก : ์ต๋๊ณต์ฝ์๋ฅผ ๊ตฌํ ๋ ์ ํด๋ฆฌ๋ ํธ์ ๋ฒ์ ์ด์ฉํ์
-
[Java] ๋ฐฑ์ค 1110๋ฒ ๋ํ๊ธฐ ์ฌ์ดํดAlgorithm/๋ฐฑ์ค 2020. 2. 19. 17:45
๋ฌธ์ ์ ๊ทผ๋ฐฉ๋ฒ 1. ์๋ก์ด ์์ ์ญ์ ์๋ฆฟ์ = input์ ์ผ์ ์๋ฆฟ์ 2. ์๋ก์ด ์์ ์ผ์ ์๋ฆฟ์ = ( input์ ์ญ์ ์๋ฆฟ์ + input์ ์ผ์ ์๋ฆฟ์ ) ์ ์ผ์ ์๋ฆฟ์ 3. ์๋ก์ด ์ = input ๋ฉ์ถ๊ธฐ ํด๊ฒฐ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 import java.io.*; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int input = Integer.parseInt(br.readLine()..