Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define nl "\n"
- #define fi first
- #define se second
- #define pb push_back
- #define ll long long
- #define RV return void
- #define sz(x) int(x.size())
- #define all(v) v.begin(), v.end()
- #define rall(v) v.rbegin(), v.rend()
- #define fixed(n) fixed << setprecision(n)
- #define cin(v) for(auto&x:v) cin >> x;
- #define cout(v) for(auto&x:v) cout << x << " ";
- void files(){
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- }
- const ll mod = (ll) (1e9+7);
- ll up(ll a , ll b ){
- return (( a % mod ) * ( b % mod) ) %mod;
- }
- ll Binex(ll a , ll b ){
- ll ret=1;
- while(b){
- if(b & 1 ) ret = up( ret, a);
- a= up(a , a );
- b>>=1;
- }
- return ret;
- }
- void solve(){
- ll n , x;
- cin >> n >> x;
- vector < ll > v(n);
- map < ll , ll > freq , mp;
- for(auto& q : v){
- cin >> q;
- freq[q]++;
- }
- for(int i =1 ; i * i <= x ; i++){
- if(x % i ==0){
- mp[i] += freq[i];
- if(i * i != x)
- mp[x/i]+=freq[x/i];
- }
- }
- ll cnt=0 , ans=0 , c=0;
- for(auto& [f,s] : mp) cnt +=s;
- for(auto& [f,s] : mp){
- if(!s) continue;
- for(auto& [f2,s2] : mp){
- if(f2 >= f) break;
- if(!s2) continue;
- if(f % f2 !=0 ){
- ll temp =((Binex(2,s) -1)* (Binex(2,s2)-1) ) % mod * (Binex(2 ,max(0ll , cnt - s -s2 - freq[x])) );
- temp %= mod;
- ans += temp;
- ans %= mod;
- // cout << f << " " << f2 << " " << temp << nl;
- if(Binex(2,s) -1)
- c++;
- }
- }
- }
- ans += up(Binex(2 , cnt - freq[x]) -1, Binex(2 , freq[x]) - 1 );
- ans %= mod;
- ans += Binex(2 , freq[x]) - 1;
- ans %= mod;
- if(c > 1) ans -=c-1;
- ans += mod;
- ans %= mod;
- // cout << c << " " ;
- cout << ans << nl;
- }
- int main(){
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- // files();
- int testCase=1;
- cin >> testCase ;
- for(int i=1 ; i <= testCase ; i++){
- // cout << "Case "<< i <<": " << nl;
- solve();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement