Ad
  • Custom User Avatar

    Similar to most other solutions, I discovered that you could use a simple mathematical formula to derive the result. However, none of the solutions I found dealt with the fact that the functions would return an incorrect value if 'n' was too large. For example, pass in UInt64.MaxValue and you will get a response which is incorrect because C# simply wraps large values around its max.

    Does anoyne have a thought on how to address this? I had attempted to set the equations equal to UInt64.MaxValue and then solve for 'n' to see if that would provide a constant limit... but my math-fu is too weak for this. Besides, I am not sure if this is the best apporach since C# may exceed the MaxValue while in the middle of computing the result... say by simply evaluating "n * n" before it ever gets to the division.

  • Custom User Avatar

    Sorry, but I cannot explain the math myself. Here is a reference though if you are interested: https://en.wikipedia.org/wiki/Square_pyramidal_number