Help ! in solving the problem in DSA series

In the DSA learning series, while doing problems, it successfully gives correct output for all public test cases, but it gives the Wrong answer while submitting the code. could someone help with this problem? This problem is about sum is everywhere (sum of the first n even and odd numbers)

Help me I’m stuck for a long time.

[Contest Page | CodeChef](https://sum is everywhere)

#include<bits/stdc++.h>
using namespace std;
int evensum(int n){
int cur=2,sum=0;
for(int i=1;i<=n;i++){
sum+=cur;
cur +=2;
}
return sum;
}
int oddsum(int n){
int cur=1,sum=0;
for(int i=1;i<=n;i++){
sum+=cur;
cur +=2;
}
return sum;
}
int main(){
int n;
cin>>n;
if(n>0)cout<<oddsum(n)<<" "<<evensum(n)<<endl;
return 0;
}

Please link to the Problem.

1 Like

Sum Is Everywhere | CodeChef

1 Like

here’s the link help me dude!

For large values of N, even_sum and odd_sum will not fit in Integer. You should use long long int.

2 Likes

use 2*n instead of n in the loop

for(int i=1;i<=2*n;i++){
Conditions;
}

1 Like