Only test case 3 is working
@deepgarg46 as Mentioned in the question you have to give answer in the form of (ans%10^9+7). So everytime you are changing your and variable then use this operation and use long variable for storing answer since it can be ver large.
i did change but again same error
@deepgarg46 As mentioned in previous reply you need to modulo it everytime you update in the loop and you have to use LONG variable.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.
i try to much but did not clear how to take ans in for loop
@deepgarg46 Fully corrected code :
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int r = sc.nextInt();
long l = (long)(Math.pow(10,9)+7);
for (int i = 0; i <r; i++) {
int m = sc.nextInt();
int n = sc.nextInt();
long[] dp = new long[m + 1];
for (int j = 1; j <= m; j++) {
if (j < n) {
dp[j] = 1;
} else if (j == n) {
dp[j] = 2;
} else {
dp[j] = dp[j- 1] + dp[j- n];
}
dp[j] %= l;
}
System.out.println(dp[m]);
}
}
}