import java.util.*;
public class Main {
public static int mod = 1000000007;
public static int f(int n, int m) {
// base case
if (n == 1 || n == 0) return 1;
// recursion
int x = 0, y = 0;
if (n >= m) x = f(n - m, m);
y = f(n - 1, m);
return (x % mod + y % mod) % mod;
}
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t != 0) {
t -= 1;
int n = sc.nextInt();
int m = sc.nextInt();
System.out.println(f(n, m));
}
}
}
What is worng with my approach except TLE since n is very large.
It’s giving me Run time error i don’t know why.