Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- using namespace std;
- using namespace __gnu_pbds;
- #define ll long long
- #define OO 2'000'000'000
- #define ull unsigned long long
- #define nl '\n'
- #define sz(x) (ll)(x.size())
- #define all(x) x.begin(),x.end()
- #define rall(s) s.rbegin(), s.rend()
- #define getline(s) getline(cin>>ws,s)
- #define ceill(n, m) (((n) / (m)) + ((n) % (m) ? 1 : 0))
- #define pi 3.141592653589793
- #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
- #define multi_ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
- void Fast_IO(){
- ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
- // freopen("filename.in", "r", stdin);
- // freopen("filename.out", "w", stdout);
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
- #endif
- }
- int dx[] = { 2, 1, -1, -2, -2, -1, 1, 2 };
- int dy[] = { 1, 2, 2, 1, -1, -2, -2, -1 };
- const ll mod = 1e9+7;
- ll fast_pow(ll a, ll b){
- ll res = 1;
- while(b){
- if(b&1) res = (res*a)%mod;
- a = (a*a)%mod;
- b>>=1;
- }
- return res;
- }
- ll n,x,ans=0;
- vector<vector<ll>> dice;
- map<ll,ll>mp;
- void sol(int l,int r,bool f,ll val){
- if(l>r){
- if(f) mp[val%mod]++;
- else{
- ans+=mp[(x*fast_pow(val,mod-2))%mod];
- }
- return;
- }
- for(int i=0;i<6;i++){
- sol(l+1,r,f,(val*dice[l][i])%mod);
- }
- }
- void solve(){
- cin>>n>>x;
- dice = vector<vector<ll>>(n,vector<ll>(6));
- for(int i=0;i<n;i++){
- for(int j=0;j<6;j++){
- cin>>dice[i][j];
- }
- }
- sol(0,n/2,1,1);
- sol(n/2+1,n-1,0,1);
- cout<<ans<<nl;
- mp.clear();
- ans = 0;
- }
- int main(){
- Fast_IO();
- int t =1;
- cin>>t;
- while(t--){
- solve();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement