My issue
In this question, why did my logic fail?
include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
long long t,n,k,x;
cin >> t;
while(t–){
cin >> n >> k >> x;
long long sum = 0, total = 1;
for(long long i = 1; i < k; i++){
sum += total;
total = sum + 1;
}
if(total <= x) cout << “yes” << endl;
else cout << “no” << endl;
}
}
My code
#include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
long long t,n,k,x;
cin >> t;
while(t--){
cin >> n >> k >> x;
long long sum = 0, total = 1;
for(long long i = 1; i < k; i++){
sum += total;
total = sum + 1;
}
if(total <= x) cout << "yes" << endl;
else cout << "no" << endl;
}
}
Problem Link: Superincreasing Practice Coding Problem - CodeChef