baekjoon 20251219
This commit is contained in:
parent
c1032afba1
commit
2523bdda53
14
code_study/Baekjoon/java/_2845.java
Normal file
14
code_study/Baekjoon/java/_2845.java
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
33
code_study/Baekjoon/ts/1644.ts
Normal file
33
code_study/Baekjoon/ts/1644.ts
Normal 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);
|
||||||
Loading…
x
Reference in New Issue
Block a user