Help me in solving SUPINC problem

My issue

include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);

ll t;
cin >> t;
while (t--) {
    ll n, k, x, sum = 0;
    cin >> n >> k >> x;
    sum = (1 LL << (k - 1));
    if (x >= sum)
        cout << "YES" << "\n";
    else
        cout << "NO" << "\n";
}

return 0;

}

why is my code incorrect

My code

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll t;
    cin >> t;
    while (t--) {
        ll n, k, x, sum = 0;
        cin >> n >> k >> x;
        sum = (1 LL << (k - 1));
        if (x >= sum)
            cout << "YES" << "\n";
        else
            cout << "NO" << "\n";
    }

    return 0;
}

Problem Link: Superincreasing Practice Coding Problem - CodeChef

i believe it is because of integer overflow
1ll<<(k-1) will return true values only till k=64 or 65 maybe but the problem asks us for k till 1e5 i believe
u can change to a language which can deal in large numbers such as python (which i did and it worked i still doubt that how it allows to deal with such large numbers but yes i got accepted)
although the simpler version for c++ would be that u ignore (1ll<<(k-1)) {ignore means do not calculate} if k>31 or 32 (u can check which one fits in the range of question)
as beyond that the range for x would be smaller than 2^(k-1)
I hope i answered your question

1 Like