### Smart ways to solve an equation in C++

Posted:

**Mon Mar 29, 2010 3:41 pm UTC**I've decided to learn C++ a couple of days ago. To help me learn the language I've started to do a couple of Project Euler problems in C++. At the moment I'm working at problem 44 (http://projecteuler.net/index.php?section=problems&id=44).

As part of the solution I have to write a function that, given a positive integer m, finds an integer n such that the equation m = n(3n-1)/2 holds.

Since I'm not very good at programming and computer-assisted problem solving I was wondering if you guys could give me tips as to how efficient I could do this. Ofcourse, the most naive way of doing this is using a for loop where n starts at 1 and increments by one every iteration. However I have the nagging feeling that this could be done a lot quicker. Thanks in advance for any hints you guys could give me!

As part of the solution I have to write a function that, given a positive integer m, finds an integer n such that the equation m = n(3n-1)/2 holds.

Since I'm not very good at programming and computer-assisted problem solving I was wondering if you guys could give me tips as to how efficient I could do this. Ofcourse, the most naive way of doing this is using a for loop where n starts at 1 and increments by one every iteration. However I have the nagging feeling that this could be done a lot quicker. Thanks in advance for any hints you guys could give me!