Skip to content

Commit 5aab6b1

Browse files
[BOJ] 9711 피보나치 (S3)
1 parent ff4f3d0 commit 5aab6b1

File tree

2 files changed

+32
-8
lines changed

2 files changed

+32
-8
lines changed

서정우/7주차/260210.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const fs = require("fs");
2+
const filePath =
3+
process.platform === "linux" ? "/dev/stdin" : "./서정우/input.txt";
4+
const input = fs.readFileSync(filePath).toString().trim().split("\n");
5+
const N = Number(input[0]);
6+
7+
for (let i = 1; i <= N; i++) {
8+
const [P, Q] = input[i].split(" ").map(Number);
9+
10+
if (P === 1 || P === 2) {
11+
console.log(`Case #${i}: ${1 % Q}`);
12+
continue;
13+
}
14+
let prev = 1,
15+
curr = 1;
16+
for (let j = 3; j <= P; j++) {
17+
[prev, curr] = [curr, (prev + curr) % Q];
18+
}
19+
console.log(`Case #${i}: ${curr}`);
20+
}

서정우/input.txt

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
7 8
2-
0 0 1 1 0 0 0 0
3-
0 1 1 1 1 0 1 0
4-
1 1 1 1 1 1 1 1
5-
0 1 1 1 1 1 0 0
6-
1 1 0 0 0 1 0 0
7-
0 1 0 0 0 1 0 1
8-
0 0 1 1 1 1 0 0
1+
11
2+
5 10
3+
6 25
4+
10 21
5+
32 43
6+
100 100
7+
50 50
8+
25 25
9+
45 67
10+
109 32
11+
128 128
12+
1 1

0 commit comments

Comments
 (0)