丑数的因子只能是2,3,5。但是可能有多个2,多个3,多个5.因此需要循环地除以2、3、5.
public class Solution {public bool IsUgly(int n) {if (n <= 0) {return false;}int[] factors = {2, 3, 5};for ( int i=0;i<3;i++) {int factor=factors[i];while (n % factor == 0) {n /= factor;}}return n == 1;}
}