Skip to main content
edited body
Source Link
thepace
  • 2.3k
  • 10
  • 10

A few notes to increase the performance INSIGNIFICANTLY:

  • Calculating MULTIPLES[0]*MULTIPLES[1] two times can be avoided by using a variable.
  • Using Bitwise operation >>2>>1 to divide the product of i * (i+1).
  • Calculating MAX_NUMBER - 1 2 times can be avoided as well.

To make the program generic for multiple multiples, you may have to make manifold changes i.e

  • to get pairs, triples, etc => All permutation of lengths 1 to multiples.size().
  • Decide when to add or subtract.

Suggestion would be to check the formula for size 3,4,5; Conclude a generic formula instead of if checks for each length and then extend it. Do include if the multiples size is 1 :-)

A few notes to increase the performance INSIGNIFICANTLY:

  • Calculating MULTIPLES[0]*MULTIPLES[1] two times can be avoided by using a variable.
  • Using Bitwise operation >>2 to divide the product of i * (i+1).
  • Calculating MAX_NUMBER - 1 2 times can be avoided as well.

To make the program generic for multiple multiples, you may have to make manifold changes i.e

  • to get pairs, triples, etc => All permutation of lengths 1 to multiples.size().
  • Decide when to add or subtract.

Suggestion would be to check the formula for size 3,4,5; Conclude a generic formula instead of if checks for each length and then extend it. Do include if the multiples size is 1 :-)

A few notes to increase the performance INSIGNIFICANTLY:

  • Calculating MULTIPLES[0]*MULTIPLES[1] two times can be avoided by using a variable.
  • Using Bitwise operation >>1 to divide the product of i * (i+1).
  • Calculating MAX_NUMBER - 1 2 times can be avoided as well.

To make the program generic for multiple multiples, you may have to make manifold changes i.e

  • to get pairs, triples, etc => All permutation of lengths 1 to multiples.size().
  • Decide when to add or subtract.

Suggestion would be to check the formula for size 3,4,5; Conclude a generic formula instead of if checks for each length and then extend it. Do include if the multiples size is 1 :-)

Source Link
thepace
  • 2.3k
  • 10
  • 10

A few notes to increase the performance INSIGNIFICANTLY:

  • Calculating MULTIPLES[0]*MULTIPLES[1] two times can be avoided by using a variable.
  • Using Bitwise operation >>2 to divide the product of i * (i+1).
  • Calculating MAX_NUMBER - 1 2 times can be avoided as well.

To make the program generic for multiple multiples, you may have to make manifold changes i.e

  • to get pairs, triples, etc => All permutation of lengths 1 to multiples.size().
  • Decide when to add or subtract.

Suggestion would be to check the formula for size 3,4,5; Conclude a generic formula instead of if checks for each length and then extend it. Do include if the multiples size is 1 :-)