Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis+ 19
How to factorize the square root that is not exact in java?
I need my program to do the following: TRANSFORM THE SQUARE ROOT OF EIGHT IN 2 ROOT OF 2
1 Resposta
+ 3
ā(a * bĀ²) = (āa) * b, right?
So what you want to do is split your number into all its prime factors, and see which ones appear twice. Those ones you can "pull out" of the square root. For example:
252 = 2 * 2 * 3 * 3 * 7 = 2Ā² * 3Ā² * 7, so
ā252 = ā(2Ā² * 3Ā² * 7) = 2 * 3 * ā7 = 6 * ā7
Another way to do it which might be simpler in code (but does the same thing), is to try all the square numbers smaller than āx and see if they divide. For example:
ā252 = 15.874... so we try all the square numbers smaller than 15.874..., from largest to smallest.
Does 9 = 3Ā² divide 252? Yes. So we put 3 into a list.
We continue with 252/9 = 28.
Does 4 = 2Ā² divide 28? Yes. So we put 2 into the list.
We continue with 28/4 = 7.
(We skip 1 = 1Ā², everything is divisible by 1)
Our list is [2, 3]. 7 is left over. So we have
ā252 = 2 * 3 * ā7 = 6 * ā7
Hope that helps.