Advertisement
Ahmed_Negm

Untitled

Aug 12th, 2023
1,154
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.86 KB | None | 1 0
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. #include <ext/pb_ds/tree_policy.hpp>
  4. using namespace std;
  5. using namespace __gnu_pbds;
  6. #define ll long long
  7. #define OO 2'000'000'000
  8. #define ull unsigned long long
  9. #define nl '\n'
  10. #define sz(x) (ll)(x.size())
  11. #define all(x) x.begin(),x.end()
  12. #define rall(s)  s.rbegin(), s.rend()
  13. #define getline(s) getline(cin>>ws,s)
  14. #define ceill(n, m) (((n) / (m)) + ((n) % (m) ? 1 : 0))
  15. #define pi  3.141592653589793
  16. #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
  17. #define multi_ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
  18.  
  19.  
  20. void Fast_IO(){
  21. ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  22. // freopen("filename.in", "r", stdin);
  23. // freopen("filename.out", "w", stdout);
  24. #ifndef ONLINE_JUDGE
  25. freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  26. #endif
  27. }
  28.  
  29.  
  30.  
  31.  
  32. int dx[] = { 2, 1, -1, -2, -2, -1, 1, 2 };
  33. int dy[] = { 1, 2, 2, 1, -1, -2, -2, -1 };
  34.  
  35. const ll mod = 1e9+7;
  36.  
  37. ll fast_pow(ll a, ll b){
  38.   ll res = 1;
  39.   while(b){
  40.     if(b&1) res = (res*a)%mod;
  41.     a = (a*a)%mod;
  42.     b>>=1;
  43.   }
  44.   return res;
  45. }
  46.  
  47. ll n,x,ans=0;
  48.  
  49.  
  50. vector<vector<ll>> dice;
  51.  
  52. map<ll,ll>mp;
  53.  
  54. void sol(int l,int r,bool f,ll val){
  55.   if(l>r){
  56.     if(f) mp[val%mod]++;
  57.     else{
  58.       ans+=mp[(x*fast_pow(val,mod-2))%mod];
  59.     }
  60.     return;
  61.   }
  62.   for(int i=0;i<6;i++){
  63.     sol(l+1,r,f,(val*dice[l][i])%mod);
  64.   }
  65. }
  66.  
  67.  
  68.  
  69. void solve(){
  70.   cin>>n>>x;
  71.   dice = vector<vector<ll>>(n,vector<ll>(6));
  72.   for(int i=0;i<n;i++){
  73.     for(int j=0;j<6;j++){
  74.       cin>>dice[i][j];
  75.     }
  76.   }
  77.   sol(0,n/2,1,1);
  78.   sol(n/2+1,n-1,0,1);
  79.   cout<<ans<<nl;
  80.   mp.clear();
  81.   ans = 0;
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88. }
  89.  
  90. int main(){
  91.     Fast_IO();
  92. int t =1;
  93. cin>>t;
  94. while(t--){
  95. solve();
  96. }
  97. return 0;
  98. }  
  99.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement