Hello there , in yesterday’s contest for division 3 I solved 3rd question and cross checked with the calculator too but it showed me wrong answer even though I met all the requirements mentioned in the question . I would be grateful if you could spare some time and help me rectify the mistake if any in my solution because I wasn’t able to recognize my mistake. Thank you!!
Below was the code I wrote and got an error:
#include
#include
#include
#include<math.h>
int main(){
int t;
std::cin>>t;
for(int i=0;i<t;i++){
int n,sum=0;
long long h=0,b=0;
std::cin>>n;
long long arr[n]={0};
if(n>1 && n<50){
for(int j=0;j<n-1;j++){
arr[j]=j+1;
sum=sum+arr[j];
}
arr[n-1]=arr[n-2];
sum=sum+arr[n-1];
h=std::pow(2,n)-sum;
for(int k=0;k<n;k++){
std::cout<<arr[k]<<" ";
}
std::cout<<h;
std::cout<<"\n";
}
else if(n>=50 && n%2==0){
for(int j=0;j<n-1;j++){
arr[j]=j+1;
sum=sum+arr[j];
}
h=std::pow(2,n-1)-sum/2;
b=h-1;
arr[n-3]++;
for(int k=0;k<n-1;k++){
std::cout<<arr[k]<<" ";
}
std::cout<<b<<" "<<h;
std::cout<<"\n";
}
else if(n>=50 && n%2!=0){
for(int j=0;j<n-1;j++){
arr[j]=j+1;
sum=sum+arr[j];
}
h=std::pow(2,n-1)-sum/2-1;
b=h-1;
arr[n-4]=arr[n-4]+2;
std::sort(arr,arr+n-1);
for(int k=0;k<n-1;k++){
std::cout<<arr[k]<<" “;
}
std::cout<<b<<” “<<h;
std::cout<<”\n";
}
else{
std::cout<<"1 1\n";
}
}
std::cin.get();
}