Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

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|improve this question
add comment

1 Answer

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|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
add comment

Your Answer

 
discard

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.