From 2523bdda53a36f1788a066c8619294206e80c5ea Mon Sep 17 00:00:00 2001 From: songyc macbook Date: Fri, 19 Dec 2025 20:56:23 +0900 Subject: [PATCH] baekjoon 20251219 --- code_study/Baekjoon/java/_2845.java | 14 ++++++++++++ code_study/Baekjoon/ts/1644.ts | 33 +++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 code_study/Baekjoon/java/_2845.java create mode 100644 code_study/Baekjoon/ts/1644.ts diff --git a/code_study/Baekjoon/java/_2845.java b/code_study/Baekjoon/java/_2845.java new file mode 100644 index 0000000..ef49e8c --- /dev/null +++ b/code_study/Baekjoon/java/_2845.java @@ -0,0 +1,14 @@ +import java.util.*; + +public class _2845 { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int L = sc.nextInt(); + int P = sc.nextInt(); + int N = L*P; + + for(int i=0; i<5; i++) System.out.printf("%d ", sc.nextInt() - N); + + sc.close(); + } +} diff --git a/code_study/Baekjoon/ts/1644.ts b/code_study/Baekjoon/ts/1644.ts new file mode 100644 index 0000000..1d6e166 --- /dev/null +++ b/code_study/Baekjoon/ts/1644.ts @@ -0,0 +1,33 @@ +export {}; +const N: number = Number(require("fs").readFileSync(0).toString().trim()); + +let isPrime: boolean[] = Array(N+1).fill(true); +isPrime[0] = false; isPrime[1] = false; + +for(let i=2; i*i <= N; i++) { + if(isPrime[i]) { + for(let j=i*i; j<=N; j+=i) isPrime[j] = false + } +} + +let nums: number[] = []; +for(let n=2; n<=N; n++) if(isPrime[n]) nums.push(n); + +let [L, R]: number[] = [0,0]; +let acc: number = nums[0]; +let count: number = 0; + +while(R < nums.length) { + if(acc === N) { + count++; + acc -= nums[L++]; + } + else if(acc > N) { + acc -= nums[L++]; + } + else { + if(++R < nums.length) acc += nums[R]; + } +} + +console.log(count); \ No newline at end of file