TWONUMBERS form COOK142 WA please help!

can some one help me this is my solution for problem code TWONUMBERS why i am getting WA

#include<bits/stdc++.h>
#define nline "\n"
#define ll long long
#define pb push_back
#define umap unordered_map
#define mod  1000000007
using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;cin>>t;
    while(t--){

    ll n;cin>>n;
    ll ans = n-2;
    if(n>6){
    	if(n%2){
    		ans = (n/2)*((n/2)+1) - 1;
    	}else{
    		if((n/2)%2){
    			ans = ((n/2)-2)*((n/2)+2) - 1;	
    		}else{
    			ans = ((n/2)-1)*((n/2)+1) - 1;	
    		}
    	}
    }
    cout<<ans<<nline;

    }

	return 0;
}


@rinkeshverma21 - the doubt solvers should be able to help you with given its difficulty rating - CodeChef

you only calculate for n>6 and assume that for n<=6, the answer is n-2, which is wrong.

N: 2, answer: 0
N: 3, answer: 1
N: 4, answer: 2
N: 5, answer: 5
N: 6, answer: 4
N: 7, answer: 11
N: 8, answer: 14

1 Like

thanks :slight_smile:

thank you very much
my code was giving WA for n = 5

1 Like

For n = 5, your code is giving 3 as answer while the correct answer is 5.

thanks