Skip to content

Commit

Permalink
Create Rohan's love for matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
dishathakurata authored Apr 23, 2024
1 parent ba0e620 commit 571ca16
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions Rohan's love for matrix
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 571ca16

Please sign in to comment.