baekjoon 20251219

This commit is contained in:
songyc macbook 2025-12-19 20:56:23 +09:00
parent c1032afba1
commit 2523bdda53
2 changed files with 47 additions and 0 deletions

View File

@ -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();
}
}

View File

@ -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);