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); + } +} +```