Description of the ugly number
A positive integer containing only the factor 2,3,5 is called an ugly number, such as 4,10,12 are ugly, and 7,23,111 is not an ugly number.
The method of judgment is first except 2, until it cannot be divisible, and then except 5 until it is divisible, and then 3 until it is not divisible. The final judgment is whether the remaining number is 1, if 1 is the ugly number, otherwise it is not the ugly number. For example 8 divided by 2 equals 4, 4 is divided by 2 equals 2, contains factor 2, so is the number of ugly. In the example 14, 14 divided by 2 equals 7 because it contains a factor of 7, not an ugly number. The ugly number can only be divisible by 2,3,5. That is, if a number is divisible by 2, we divide it by 2, and if it is divisible by 3, it is divided by 3, and if it is divisible by 5, it is divided by 5. If the last thing we get is 1, then this number is the ugly number, otherwise it's not.
- 8/2 = 4 Ugly number
- 6/2 = 3 Ugly number
- 14/2 = 7 is not an ugly number
function _isuglynb ($nums) { if (!is_numeric ($nums)) { return ' It is not a number '; } Whether it can be divisible by 2 while ($nums%2 = = 0) { $nums = $nums/2; } Whether it can be divisible by 3 while ($nums%3 = = 0) { $nums = $nums/3; } Whether it can be divisible by 5 while ($nums%5 = = 0) { $nums = $nums/5; } if ($nums = = 1) {//ugly return 1; } else{ return 0;} } echo _isuglynb (8); 1 echo _isuglynb (6); 1 echo _isuglynb (+); 0
PHP calculates the number of fools