This solution has scored 100 in Quera.
🌟 If you like this solution, please give it a star.
- If n is odd like 9, the sequence is as follows:
0 1 2 3 4 4 3 2 1 0
The sum of this sequence:
(0 + 1 + 2 + 3 + 4)
+ (0 + 1 + 2 + 3 + 4)
= 2 * ((0 + 1 + 2 + 3 + 4))
It means twice the sum of the numbers 1 to int(9/2)
- If n is even, like 10, the sequence is as follows:
0 1 2 3 4 5 4 3 2 1 0
The sum of this sequence:
(0 + 1 + 2 + 3 + 4)
+ (4 + 3 + 2 + 1 + 0)
+ 5
= 2 * (0 + 1 + 2 +3 + 4)
+ 5
That is, double the sum of the numbers 1 to (n/2)-1
and then sum it with n/2
.
- To add the numbers 1 to
n
we have:
(n * (n + 1))/2
C# .NET 5
- In the directory, run
dotnet build
dotnet run
Reach out to the maintainer at one of the following places:
The original setup of this repository is by Hamid Molareza.
This solution is licensed under the GPLv3.