fork download
  1. #include <bits/stdc++.h>
  2. const int mod = 1e9+7;
  3. long long fp(long long b, int e){
  4. if(e) return fp(b*b%mod, e>>1) * (e&1?b:1) % mod;
  5. return 1;
  6. }
  7. signed main() {
  8. std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr);
  9. int t;
  10. std::cin >> t;
  11. while(t--){
  12. int n, q;
  13. std::cin >> n >> q;
  14. while(q--){
  15. int x;
  16. std::cin >> x;
  17. long long p = 3;
  18. long long ans = 2 * x * fp(p, mod-2) % mod;
  19. for(int y =x+1; y <=n; ++y){
  20. p = p * 3 % mod;
  21. ans = (ans + y * fp(p, mod-2) % mod) % mod;
  22. }
  23. p = 3;
  24. for(int y=x-1; y; --y){
  25. p = p * 3 % mod;
  26. ans = (ans + y * fp(p, mod-2) % mod) % mod;
  27. }
  28. std::cout << ans << '\n';
  29. }
  30. }
  31. }
Success #stdin #stdout 0.01s 5324KB
stdin
1
3 1
2
stdout
777777785