Below is the code and its weird its showing its wrong , since all the test cases are getting passed.
If there is any error please let me know …
using namespace std;
int main()
{
int n;
cin >> n;
cout << ((n * (n + 1)) / 2);
return 0;
}
Below is the code and its weird its showing its wrong , since all the test cases are getting passed.
If there is any error please let me know …
using namespace std;
int main()
{
int n;
cin >> n;
cout << ((n * (n + 1)) / 2);
return 0;
}
Constraints:
1 ≤ N ≤ 10^9
Here, the maximum value of n
can be 10^9
, if we give this as input then we will get wrong answer because the value of ((n * (n + 1)) / 2);
will be larger than max. value that int
data type can store.
So, use data type with larger range, it should resolve the issue.
thanks !!