Competitive ProgrammingEasy

Sum from 1 to n

Detailed guide and Python implementation for the 'Sum from 1 to n' problem.

Problem Statement

Easy

Write a function sum_1_to_n(n) that returns the sum of integers from 1 to n.

Constraints
  • 1 <= n <= 10^5

Examples

Example 1
Input
sum_1_to_n(5)
Output
15
Explanation

1 + 2 + 3 + 4 + 5 = 15.

Example 2
Input
sum_1_to_n(10)
Output
55
Explanation

1 + 2 + ... + 10 = 55.

Need a Hint?
Consider using Dynamic Programming-specific data structures like sets or heaps.
Edge Cases to Watch
  • Empty input structures
  • Single element inputs
  • Large numerical bounds

Ready to Solve?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

Open in Editor

Recommended Python Resources

Expand your knowledge with related interactive tutorials, cheat sheets, and code comparisons.