N1VALUES - Editorial

bro can you pls tell y i am getting WA?

#include
#include<math.h>
#include
#include
using namespace std;
long long i,k;
void solve(){
long long n,power; cin>>n; vectorv;
for(i=1;i<n;i++){
if(i<=n)
v.push_back(i);
if(i==n-1){v.push_back(i);}

}
int k= accumulate(v.begin(),v.end(),0);

int po= 1ll<<n;
int m=po-k;
v.push_back(po-k);

   for(int i=0;i<n+1;i++)cout<<v[i]<<" ";
   cout<<"\n";

}
int main(){
ios::sync_with_stdio(false); cin.tie(NULL);
int tc; cin>>tc;
while(tc–>0)solve();
return 0;
}

@harshkumar007 @arikaran_02 both of yours fail on this testcase:

ok bro thnx

2 Likes

bro really thank you so much i got AC

1 Like

I faced the same problem. The problem is with n=60 and occurs due to approximation by the system. You can check that pow(2,n) and pow(2,n)-2 will yield the same values. TRY PRINTING THEM OUT. It occurs maybe because pow(2,n)-2 is negligibly small from pow(2,n) and so they are virtually treated as the same.

The C++ double type can only store integers up to 2^{53} without precision loss, as explained by this stackoverflow answer.

1 Like

Put n=60.value is very large more than 1e18.
Sorry for late reply.

1 Like

thanks

bro can you pls say y i am getting nzec error

import java.util.;
import java.lang.
;
import java.io.*;

/* Name of the class has to be β€œMain” only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner s = new Scanner(System.in);
double tcash,rem,amt;
tcash=120.00;
amt=s.nextInt();
if(amt%5==0 && amt<=tcash){
rem=tcash-amt-0.50;
System.out.println(String.format(β€œ%.2f”,rem));
}
else{
System.out.println(String.format(β€œ%.2f”,tcash));
}
}
}

can anyone tell me what’s wrong with this approach?..

import java.util.;
import java.lang.
;
import java.io.*;
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner scanner = new Scanner(System.in);
int testCases = scanner.nextInt();
while(testCases-- > 0)
{
int terms = scanner.nextInt();
if(terms+1 >= 3)
{
int i=1;
int range = terms-2;
for(;i<=range;i++)
System.out.print(i+" β€œ);
System.out.print(i+” β€œ+i+” β€œ);
System.out.println((long)(Math.pow(2,terms)-((i+1)*i/2+i)));
}
else
System.out.println(1+” "+1);
}
}
}

https://www.codechef.com/viewsolution/55096247

why this is giving a WA

#include <bits/stdc++.h>
using namespace std;

#define ll long long

int main()
{
ios::sync_with_stdio(0);
cin.tie(0);

ll t;
cin>>t;
while(t--)
{
    ll n;
    cin >> n;
    
    if(n==1) {
        cout << "1 1\n";
        continue;
    }
    
    ll x = 1 << n;
    
    for(int  i = 1 ; i<n;++i)
    {
        cout << i << " ";
        x -= i;
    }
    
    cout << n-1 << " ";
    x -= n-1;
    cout << x << "\n";
}
return 0;

}