fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long ll;
  5.  
  6. const int M = 1e9 + 7;
  7. int n, x, F[14][6], all[280000], idx;
  8. ll res;
  9.  
  10. int Pow(int a, int b) {
  11. int res = 1;
  12. while (b != 0) {
  13. if (b & 1)
  14. res = ((ll) res * a) % M;
  15. a = ((ll) a * a) % M;
  16. b >>= 1;
  17. }
  18. return res;
  19. }
  20.  
  21. inline int calc(int cur) {
  22. int L = lower_bound(all, all + idx, cur) - all;
  23. if (L == idx)
  24. return 0;
  25. return upper_bound(all, all + idx, cur) - all - L;
  26. }
  27.  
  28. void calc(int at, int cur, int E) {
  29. if (at == E) {
  30. if (E == n)
  31. res += calc(((ll) x * Pow(cur, M - 2)) % M);
  32. else
  33. all[idx++] = cur;
  34. return;
  35. }
  36. for (int i = 0; i < 6; ++i)
  37. calc(at + 1, ((ll) cur * F[at][i]) % M, E);
  38. }
  39.  
  40. int main(int argc, char **argv) {
  41. int t;
  42. scanf("%d", &t);
  43. while (t-- != 0) {
  44. scanf("%d%d", &n, &x);
  45. for (int i = 0; i < n; ++i)
  46. for (int j = 0; j < 6; ++j)
  47. scanf("%d", &F[i][j]);
  48. res = idx = 0;
  49. calc(0, 1, n >> 1);
  50. sort(all, all + idx);
  51. calc(n >> 1, 1, n);
  52. printf("%lld\n", res);
  53. }
  54. return 0;
  55. }
Success #stdin #stdout 0s 16336KB
stdin
Standard input is empty
stdout
Standard output is empty