如果最后输出的语句为 cout << ans + 1; 而不是 +1 再取模 cout << (ans + 1) % mod; 的话仍然能通过。
cout << ans + 1;
+1
cout << (ans + 1) % mod;
input
2 999999999 1000000000 5 5
wrong
1000000007
right
0