Solving problems like this is often easier using a simple trick. Memorize it. r=floor(ln42/ln2)=5. q=floor[ln(42-2^5)]=3. p=ln(42-2^5-2^3)/ln2=1. Try solving this problem: 7^p-5^q-3^r=820391, p>q>r, which seems hopeless. In this case we see that 7^p must be more than 820391, so use the ceiling function: p=ceiling(ln820391/ln7)=7. Then 5^q+3^r=7^p-820391, and 5^q must be less than 7^p-82039, so use the floor function: q=floor[ln(7^7-820391)/ln5]=5. Finally r=ln(7^7-820391-5^5)/ln3=3. This method works only if the exponent of the largest remaining term is solved for at each next step, which is the way this type of problem is usually set up. In the given problem, we know that 2^r>2^q>2^p, so solve for r first, q second, and p third. In my example, we know that 7^p>5^q>3^r, so solve for p first, q second, and r third.