From 84552d488c45bd45c9f2fa0d320c2676a7c4af12 Mon Sep 17 00:00:00 2001 From: suyeun84 <81475092+suyeun84@users.noreply.github.com> Date: Wed, 26 Feb 2025 09:53:01 +0900 Subject: [PATCH] =?UTF-8?q?[20250226]=20BOJ=20/=20=EA=B3=A8=EB=93=9C2=20/?= =?UTF-8?q?=20=ED=94=BC=EB=B3=B4=EB=82=98=EC=B9=98=20=EC=88=98=206=20/=20?= =?UTF-8?q?=EA=B9=80=EC=88=98=EC=97=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...353\202\230\354\271\230 \354\210\230 6.md" | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 "suyeun84/202502/26 BOJ G2 \355\224\274\353\263\264\353\202\230\354\271\230 \354\210\230 6.md" diff --git "a/suyeun84/202502/26 BOJ G2 \355\224\274\353\263\264\353\202\230\354\271\230 \354\210\230 6.md" "b/suyeun84/202502/26 BOJ G2 \355\224\274\353\263\264\353\202\230\354\271\230 \354\210\230 6.md" new file mode 100644 index 00000000..cca75d5d --- /dev/null +++ "b/suyeun84/202502/26 BOJ G2 \355\224\274\353\263\264\353\202\230\354\271\230 \354\210\230 6.md" @@ -0,0 +1,39 @@ +```java +import java.util.*; +import java.io.*; + +public class Main { + final static int mod = 1000000007; + static HashMap map; + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + long N = Long.parseLong(br.readLine()); + map = new HashMap<>(); + + map.put((long) 1, (long) 1); + map.put((long) 2, (long) 1); + + long answer = fibo(N); + + System.out.println(answer); + } + + static long fibo(long N) { + if (map.containsKey(N)) return map.get(N); + long a, b, c; + if (N % 2 == 1) { + a = fibo(N/2 + 1); + b = fibo(N/2); + map.put(N, ((a%mod)*(a%mod)%mod+(b%mod)*(b%mod)%mod)%mod); + } else { + a = fibo(N/2 + 1); + b = fibo(N/2); + c = fibo(N/2 - 1); + map.put(N, ((a%mod)*(b%mod)%mod+(b%mod)*(c%mod)%mod)%mod); + } + + return map.get(N); + } +} +```