fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. const long m = 1e9 + 7;
  6.  
  7. inline long fastModExpo(long a, long b) {
  8. long y = 1;
  9. while (b) {
  10. if (b & 1) {
  11. y *= a;
  12. y %= m;
  13. }
  14. b >>= 1;
  15. a *= a;
  16. a %= m;
  17. }
  18. return y;
  19. }
  20.  
  21. int main() {
  22. ios_base::sync_with_stdio(false);
  23. cin.tie(nullptr);
  24. cout.tie(nullptr);
  25. int tt;
  26. cin >> tt;
  27. while (tt--) {
  28. long n, s;
  29. cin >> n >> s;
  30. long ans = fastModExpo(n, m - 2);
  31. ans *= s;
  32. ans %= m;
  33. ans = fastModExpo(ans, n);
  34. cout << ans << '\n';
  35. }
  36. return 0;
  37. }
  38.  
Success #stdin #stdout 0s 15232KB
stdin
2
3 6
3 5
stdout
8
296296303