### My issue

Why cannot we use sum of first n natural number formula here

### My code

```
#include <stdio.h>
int main(void) {
// your code goes here
int n;
int count=0,sum=0;
scanf("%d",&n);
int arr[n];
for(int i=0;i<n;i++){
scanf("%d",&arr[i]);
count+=arr[i];
sum=sum+(i+1);
}
if(sum==count)
printf("YES\n");
else
printf("NO\n");
return 0;
}
```

Problem Link: DIVIDING Problem - CodeChef

We can use sum of first n natural number formula here.

Code :-

```
#include<bits/stdc++.h>
using namespace std;
#define int long long
int32_t main(){
int n;
cin >> n;
int sum = 0;
for(int i=0; i<n; i++){
int temp;
cin >> temp;
sum += temp;
}
if(sum == n*(n+1)/2.0){
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
return 0;
} ```
```

The code you’ve provided appears to be checking whether the sum of the elements in an array `arr`

is equal to the sum of the first `n`

natural numbers, where `n`

is the length of the array. While you can use the formula for the sum of the first `n`

natural numbers to optimize this code, you should note that the code as written also counts the index values (1, 2, 3, …) in the `sum`

variable. If you want to compare only the sum of the array elements to the sum of natural numbers, you can simplify the code.