def sum_digits(num_str, radix): ret = sum(int(digit, radix) for digit in num_str) return ret def main(): i = 1 count = 0 while True: bin_str = bin(i)[2:] oct_str = oct(i)[2:] dec_str = str(i) hex_str = hex(i)[2:] bin_sum = sum_digits(bin_str, 2) oct_sum = sum_digits(oct_str, 8) dec_sum = sum_digits(dec_str, 10) hex_sum = sum_digits(hex_str, 16) if i % bin_sum == 0 and i % oct_sum == 0 and i % dec_sum == 0 and i % hex_sum == 0: count += 1 if count == 2023: break i += 1 print(i) if __name__ == "__main__": main()
python实现哈沙德数
最新推荐文章于 2024-08-28 16:14:15 发布