Py数
1182 ワード
説明:
n=2992の場合、Yesが出力される.n=9999であればNoを出力します.
from __future__ import print_function # bin()、oct()、int()、hex() # n = 2992 def twelve(n): list = '' while n >= 12: temp = n % 12 if temp == 10: list += 'a' elif temp == 11: list += 'b' else: list += str(temp) n/= 12 list += str(n) return ''.join(reversed(list)) def pick_out(n): ret = '' n_10 = str(n) n_12 = str(twelve(n)) n_16 = str(hex(n))[2:] # print(n_12) sum_10 = 0 sum_12 = 0 sum_16 = 0 for index in n_10: sum_10 += int(index) for index in n_16: sum_16 += int(index,16) for index in n_12: sum_12 += int(index,12) if sum_12 == sum_16 and sum_16 == sum_10: ret = 'Yes' else: ret = 'No' return ret print(pick_out(n),end='')
Py , , , 2992,
, , 2+9+9+2=22, BB0, 22,
1894, 22, , 。
Py , , Py 。
4 n, n Py , , Yes, No。
n=2992の場合、Yesが出力される.n=9999であればNoを出力します.
from __future__ import print_function # bin()、oct()、int()、hex() # n = 2992 def twelve(n): list = '' while n >= 12: temp = n % 12 if temp == 10: list += 'a' elif temp == 11: list += 'b' else: list += str(temp) n/= 12 list += str(n) return ''.join(reversed(list)) def pick_out(n): ret = '' n_10 = str(n) n_12 = str(twelve(n)) n_16 = str(hex(n))[2:] # print(n_12) sum_10 = 0 sum_12 = 0 sum_16 = 0 for index in n_10: sum_10 += int(index) for index in n_16: sum_16 += int(index,16) for index in n_12: sum_12 += int(index,12) if sum_12 == sum_16 and sum_16 == sum_10: ret = 'Yes' else: ret = 'No' return ret print(pick_out(n),end='')