[閒聊]好數壞數

[閒聊]好數壞數

lskuo 於 星期三 十月 05, 2022 9:24 am


左鍵: 點擊縮放; 右鍵: 觀看原圖
左鍵: 點擊縮放; 右鍵: 觀看原圖

lskuo
專 家
專 家
 
文章: 257
註冊時間: 2010-11-10

lskuo 於 星期六 十月 08, 2022 2:27 pm


剛剛發現如果給定的區間不是49, 而是偶數D時,因為b,c為正整數的限制,使得最大好數不在b=c, 而是c = D/2, b = c-1

另外,也許有人想試試python code:

def good_integer(D):
    All_good = []
    for a in range(0,D-1):
        for b in range(a+1,D):
            for c in range(b,D):
                if b+c -a >= D:
                    continue
                d_up_bound = D+1
                if a != 0:
                    d_up_bound = min(D+1, b*c//a+1)
                for d in range(b+c-a+1,d_up_bound):
                    den = a+d - b-c
                    num = b*c - a*d
                    if den*num >0 and num % den == 0:
                        All_good.append(num//den)
    All_good_list = list(sorted(set(All_good)))
    print('The maximal good integer: ',All_good_list[-1])
    # To find the minmal bad integer
    len_all_good = len(All_good_list)
    for i in range(0,len_all_good-1):
        a = All_good_list+1
        if All_good_list[i+1] != a:
            print('The minimal bad integer: ', a)
            break
        if i == (len_all_good - 2):
            print('The minimal bad integer: ', All_good_list[-1]+1)
    print('Number of all good numbers: ', len(All_good_list))



lskuo
專 家
專 家
 
文章: 257
註冊時間: 2010-11-10




『數學及時、求救區』