fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ull unsigned long long
  4. #define ll long long int
  5. #define MOD 1000000007
  6.  
  7.  
  8. ull countSetBits (ull n)
  9. {
  10. ull count = 0;
  11. while (n) {
  12. count += n & 1;
  13. n >>= 1;
  14. }
  15. return count;
  16. }
  17.  
  18.  
  19. ull power(ull x, ull y, ull p)
  20. {
  21. ull res = 1; // Initialize result
  22.  
  23. x = x % p; // Update x if it is more than or
  24. // equal to p
  25.  
  26. while (y > 0)
  27. {
  28. // If y is odd, multiply x with result
  29. if (y & 1)
  30. res = (res*x) % p;
  31.  
  32. // y must be even now
  33. y = y>>1; // y = y/2
  34. x = (x*x) % p;
  35. }
  36. return res;
  37. }
  38.  
  39.  
  40.  
  41. int main() {
  42. ios_base::sync_with_stdio(false);
  43. cin.tie(NULL);
  44. int t;cin>>t;ull a[50007];int n;ull ans=1;ull c;ull num;
  45. while(t--){
  46. cin>>n;
  47. ans=1;
  48. int flag=1;
  49. for(int i=0;i<n;i++){
  50. cin>>a[i];
  51. }
  52. for(int i=0; i<n-1; i++) {
  53. if((a[i]&a[i+1])!=a[i]) {
  54. cout << "0"<<endl;
  55. flag=0;
  56. break;
  57. }
  58. }
  59.  
  60. if(flag==0){
  61. continue;
  62. }
  63.  
  64. for(int i=1;i<=n;i++){
  65. num=a[i]&a[i-1];
  66. c=countSetBits(num);
  67. ans=(ans*power(2,c,MOD))%MOD;
  68. }
  69. cout<<ans<<endl;
  70. }
  71.  
  72. return 0;
  73. }
  74.  
Success #stdin #stdout 0s 4472KB
stdin
Standard input is empty
stdout
Standard output is empty