白話來說,就是把測資去掉所有2、3、5的因數後,如果只剩下1,就顯示ugly,反之顯示beautiful,這邊就運用while來重複檢測輸入是否尚能被2、3、5整除,如果可以就將其整除後再檢查一次,直到不能在除2、3、5為止。
程式碼如下:
def t():
n = int(input())
while n % 2 == 0:
n //= 2
while n % 3 == 0:
n //= 3
while n % 5 == 0:
n //= 5
if n == 1:
print('ugly')
else:
print('beautiful')
t()
沒有留言:
張貼留言