1559A - Mocha and Math - CodeForces Solution


bitmasks constructive algorithms math *900

Please click on ads to support us..

Python Code:

for _ in range(int(input())):
    n = int(input())
    a=list(map(int,input().split()))
    ans=a[0]
    for i in a: 
        ans&=i
    print(ans)

C++ Code:

#include <bits/stdc++.h>
using namespace std;
#define nl cout << "\n";
#define getunique(v)                                  \
    {                                                 \
        sort(v.begin(), v.end());                     \
        v.erase(unique(v.begin(), v.end()), v.end()); \
    }
#define forn(a, b) for (int i = a; i < b; i++)
#define popcountll __builtin_popcountll
#define ctzll __builtin_ctzll
#define pii pair<int, int>
#define mp(a, b) make_pair(a, b)
#define pb push_back
#define all(a) a.begin(), a.end()
#define vi vector<int>
#define hhh cout << "here" << endl;
#define int long long int
#define ld long double
#define mod1 1000000007
#define mod2 998244353
void solve()
{
    int n;
    cin >> n;
    vi a(n);
    int ans = (2ll << 33) - 1;
    forn(0, n)
    {
        cin >> a[i];
        ans &= a[i];
    }
    cout << ans;
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t = 1;
    cin >> t;
    while (t--)
    {
        solve();
        nl;
    }
    return 0;
}


Comments

Submit
0 Comments
More Questions

1452A - Robot Program
344A - Magnets
96A - Football
702B - Powers of Two
1036A - Function Height
443A - Anton and Letters
1478B - Nezzar and Lucky Number
228A - Is your horseshoe on the other hoof
122A - Lucky Division
1611C - Polycarp Recovers the Permutation
432A - Choosing Teams
758A - Holiday Of Equality
1650C - Weight of the System of Nested Segments
1097A - Gennady and a Card Game
248A - Cupboards
1641A - Great Sequence
1537A - Arithmetic Array
1370A - Maximum GCD
149A - Business trip
34A - Reconnaissance 2
59A - Word
462B - Appleman and Card Game
1560C - Infinity Table
1605C - Dominant Character
1399A - Remove Smallest
208A - Dubstep
1581A - CQXYM Count Permutations
337A - Puzzles
495A - Digital Counter
796A - Buying A House