[PR #1485] Add O(1) optimized solution for Project Euler Problem 6 #hacktoberfest #2087

Closed
opened 2026-01-29 15:28:31 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/TheAlgorithms/C/pull/1485

State: closed
Merged: No


Description

This PR adds an O(1) optimized solution for Project Euler Problem 6 in C.
It uses the mathematical formulas:

  • Sum of squares = n(n+1)(2n+1)/6
  • Square of sum = (n(n+1)/2)^2

Changes

  • Added new file o(1)sol.c in project_euler/problem_6/
  • Provides a faster O(1) implementation compared to iterative methods
  • Included comments and example usage for better understanding

Example

Input:
100

Output:
25164150

Notes

  • Uses long long to avoid overflow for larger values of n
  • Code is well-documented to support educational use

Thank you for reviewing this contribution 🚀

**Original Pull Request:** https://github.com/TheAlgorithms/C/pull/1485 **State:** closed **Merged:** No --- ## Description This PR adds an O(1) optimized solution for Project Euler Problem 6 in C. It uses the mathematical formulas: - Sum of squares = n(n+1)(2n+1)/6 - Square of sum = (n(n+1)/2)^2 ## Changes - Added new file `o(1)sol.c` in `project_euler/problem_6/` - Provides a faster O(1) implementation compared to iterative methods - Included comments and example usage for better understanding ## Example Input: 100 Output: 25164150 ## Notes - Uses `long long` to avoid overflow for larger values of `n` - Code is well-documented to support educational use Thank you for reviewing this contribution 🚀
claunia added the pull-request label 2026-01-29 15:28:31 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/C#2087