Skip to content

Conversation

KRiSHnA88H
Copy link

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 🚀

@KRiSHnA88H KRiSHnA88H changed the title Add O(1) optimized solution for Project Euler Problem 6 Add O(1) optimized solution for Project Euler Problem 6 #hacktoberfest Oct 1, 2025
@KRiSHnA88H KRiSHnA88H closed this Oct 1, 2025
@KRiSHnA88H KRiSHnA88H reopened this Oct 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants