~cpp
def divisor(target, div):
    if target < div:
        return target
    while target % div == 0:
        target /= div
    return target

def isUgly(target):
    target = divisor(target, 2)
    target = divisor(target, 5)
    target = divisor(target, 3)    
    if target != 1:
        return False
    return True

n = 1
count = 1;
while count != 1500:
    if isUgly(n):
        print n , count
        count+=1
    n+=1
print n-1

UglyNumbers
Retrieved from http://wiki.zeropage.org/wiki.php/UglyNumbers/승한
last modified 2021-02-07 05:28:20