We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 65e4a63 commit 515986eCopy full SHA for 515986e
1 file changed
2025-09-03/김대환/프로그래머스_피보나치수.java
@@ -0,0 +1,23 @@
1
+// n번째 피보나치 수를 1234567로 나눈 나머지 반환
2
+class Solution {
3
+ private static final int MOD = 1234567;
4
+
5
+ public int solution(int n) {
6
+ return fibMod(n);
7
+ }
8
9
+ private int fibMod(int n) {
10
+ if (n == 0) return 0; // F(0)
11
+ if (n == 1) return 1; // F(1)
12
13
+ long a = 0; // F(0)
14
+ long b = 1; // F(1)
15
16
+ for (int i = 2; i <= n; i++) {
17
+ long sum = (a + b) % MOD; // 합을 long으로 계산
18
+ a = b;
19
+ b = sum;
20
21
+ return (int)(b % MOD);
22
23
+}
0 commit comments