Sum of Squares
Sum of Squares
EasyMath77% accepted
Given N, compute the sum 1² + 2² + 3² + ... + N². For example, if N=3 the sum is 1 + 4 + 9 = 14. You can use a loop or the direct formula N*(N+1)*(2N+1)/6. This is a classic math problem that appears in competitive programming.
Approach
Given N, print the sum of squares: 1² + 2² + ... + N².
Input
1
Output
1
More Math problems
Browse all coding problems →solution.py
Loading editor...
Test 1
Test 2
Test 3
Press Run to test your custom input, or Submit to judge against all test cases.
Sign in to continue
Create a free account to run code, submit solutions and track progress.
- Free forever — no credit card
- 10+ languages with live execution
- Points, streaks & leaderboards