Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Given $r$ and $t$, Is there a way to find the maximum positive integer $N$ such that:

$$2 N^2 + (2r+3)N + (2r+1) \leq t$$

I want to write a program to solve that inequality without brute-force. At least the program should be as fast as possible.

share|cite|improve this question
up vote 3 down vote accepted

Use the quadratic formula and floor the result(s):

In standard form: $0 = ax^2 + bx + c$

$a = 2$

$b = (2r + 3)$

$c = (2r + 1 - t)$

share|cite|improve this answer
I tried but I didn't get the correct answer for r = 1 and t = 10. Answer should be 2 and I got 1. – Osama Gamal Apr 27 '13 at 21:42
For $r=1$ and $N=1$ the LHS is exactly 10, so 1 is the right answer. – thesamet Apr 27 '13 at 21:44
I guess I got the wrong inequality from the beginning :) Thanks – Osama Gamal Apr 27 '13 at 21:47

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.