# 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.

[CodeChef: Practical coding for everyone](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;
}

1 Like
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.

4 Likes

use 2*n instead of n in the loop

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

2 Likes

i did with n*2 only in the beginning then it didn’t accept my code then this 2 loops method still not after using long long it accepted. Why we need to use this why int is not sufficient it has a wide range right

The range of int is

-2,147,483,647 to 2,147,483,647


But the answer to the problem is as big as 10^6\times 10^6 = 10^{12}. Hence it will not fit in an Integer.

1 Like