fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long int
  4. #define double long double
  5.  
  6.  
  7. const int M = 1000000007;
  8. const int N = 3e5+9;
  9. const int INF = 2e9+1;
  10. const int LINF = 2000000000000000001;
  11.  
  12.  
  13. inline int power(int a, int b) {
  14. a %= M;
  15. int x = 1;
  16. while (b) {
  17. if (b & 1) x = (x*a)%M;
  18. a = (a*a)%M;
  19. b >>= 1;
  20. }
  21. return x;
  22. }
  23.  
  24.  
  25.  
  26. //_ ***************************** START Below *******************************
  27.  
  28.  
  29.  
  30. int mod_div(int a, int b){
  31. return (a * power(b, M-2))%M;
  32. }
  33.  
  34.  
  35.  
  36. int mod_sub(int a, int b){
  37. return (a - b + M)%M;
  38. }
  39.  
  40. vector<vector<int>> a;
  41. void consistency(int n){
  42.  
  43. int count = 1;
  44. int sum = 1;
  45. int product = 1;
  46. int y = 1;
  47.  
  48. //* Count
  49. for(int i=0; i<n; i++){
  50. int p = a[i][0];
  51. int e = a[i][1];
  52. count = (count * (e+1))%M;
  53.  
  54. //* This will be future expo, hence modulo (M-1) or Rather 2(M-1)
  55. y = (y * (e+1)) % (2*(M-1));
  56. }
  57.  
  58. //* Sum
  59. for(int i=0; i<n; i++){
  60. int p = a[i][0];
  61. int e = a[i][1];
  62. int nmr = mod_sub(power(p, e+1 ) , 1 );
  63. int dnr = mod_sub(p, 1);
  64.  
  65. int val = mod_div(nmr, dnr);
  66.  
  67. sum = (sum * val)%M;
  68.  
  69. }
  70.  
  71. //* product
  72. for(int i=0; i<n; i++){
  73. int p = a[i][0];
  74. int e = a[i][1];
  75.  
  76. //* Can't Use modular inverse : (e% M-1) * (y % M-1) * (2^-1) % M-1
  77. //* cz M-1 is not Prime no. so Fermats theorem not applicable,
  78. //* hence 1st compute then apply Mod
  79. int exponent = ((e*y)/2)%(M-1);
  80. int val = power(p, exponent);
  81.  
  82. product = (product * val)%M;
  83.  
  84. }
  85.  
  86. cout << count << " " << sum << " " << product << endl;
  87.  
  88. }
  89.  
  90. void solve() {
  91.  
  92.  
  93. int n;
  94. cin>>n;
  95. a.resize(n);
  96. for(int i=0; i<n; i++){
  97. int x, y;
  98. cin >> x >> y;
  99. a[i] = {x, y};
  100. }
  101. consistency(n);
  102.  
  103.  
  104. }
  105.  
  106.  
  107.  
  108.  
  109.  
  110. int32_t main() {
  111. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  112.  
  113.  
  114. int t = 1;
  115. cin >> t;
  116. while (t--) {
  117. solve();
  118. }
  119.  
  120. return 0;
  121. }
Success #stdin #stdout 0.01s 5320KB
stdin
2
1
2 1
4
2 7
3 5
7 1
13 2
stdout
2 3 2
288 135888480 441880102