php - Get factors of a number -
I need to get two factors (x) of given number (x):
< Ul>Example:
- n = 16 => x = 4, y = 4
- n = 17 => x = 4 , = Y = 4
- = 18 => x = 6, y = 3
- n = 20 => x = 5, y = 4
Any language but primarily PHP will do.
Edit - Clarification
I want to make a rectangle, the width of X units * y units are high that its area is close to possible as n to X and Y integer if n is a prime number then the factors of n - 1 are acceptable.
Your specifics were not enough, you had said that you wanted the factors, yet your tests In the case of 4 is not a component of 17
The following pseudo code prefixes that a factor accurate (if (N modulo I) == For the range i {range (sqrt (n)), 1) / code>
i.e. <{x = iy = round (n / i}}}
A simple SQL Statement will work to ensure that the number is The ni is close together, meets together, but does not guarantee that they are the factor.
Comments
Post a Comment