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