diff --git a/Rohan's love for matrix b/Rohan's love for matrix new file mode 100644 index 0000000..dc307c9 --- /dev/null +++ b/Rohan's love for matrix @@ -0,0 +1,35 @@ +//Rohan's love for matrix + +import java.io.*; +import java.util.*; + +class GFG { + public static void main(String args[]) throws IOException { + BufferedReader read = new BufferedReader(new InputStreamReader(System.in)); + int t = Integer.parseInt(read.readLine()); + + while(t-- > 0) { + int n = Integer.parseInt(read.readLine()); + Solution ob = new Solution(); + System.out.println(ob.firstElement(n)); + } + } +} + +class Solution { + static int firstElement(int n) { + if(n == 1 || n == 2) { + return 1; + } + + int a = 1, b = 1, ans = 0, mod = 1000000007; + + for(int i = 3; i <= n; i++) { + ans = (a + b) % mod; + a = b; + b = ans; + } + + return ans; + } +}