結果

問題 No.6 使いものにならないハッシュ
ユーザー szkhts
提出日時 2020-07-24 11:54:47
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 788 ms / 5,000 ms
コード長 1,162 bytes
コンパイル時間 127 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 13,568 KB
最終ジャッジ日時 2024-09-16 16:58:26
合計ジャッジ時間 12,394 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

def make_prime(f, t):
    prime_list = []

    for i in range(f, t + 1):
        if i == 1:
            continue
        isPrime = True
        j = 2
        while j * j <= i:
            if i % j == 0:
                isPrime = False
                break
            j += 1
        if isPrime:
            prime_list.append(i)
        
    return prime_list;

def calc(p):
    sum = 0
    while p > 0:
        sum += p % 10
        p = p // 10
    if sum >= 10:
        sum = calc(sum)
    return sum
    
K = int(input())
N = int(input())
prime_list = make_prime(K, N)

calc_result = []
for p in prime_list:
    calc_result.append(calc(p))
    
hash_list = []
for i in range(len(calc_result)):
    temp = [calc_result[i]]
    length = 1
    s_idx = i
    for j in range(i + 1, len(calc_result)):
        if calc_result[j] in temp:
            break
        else:
            length += 1
            temp.append(calc_result[j])
    hash_list.append([s_idx, length])            

max_sum = 0
max_idx = 0
for hash_item in hash_list:
    if hash_item[1] >= max_sum:
        max_sum = hash_item[1]
        max_idx = hash_item[0]
        
print(prime_list[max_idx])
0