結果

問題 No.6 使いものにならないハッシュ
ユーザー sue_charo
提出日時 2017-04-27 14:42:36
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,517 bytes
コンパイル時間 144 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 12,288 KB
最終ジャッジ日時 2024-09-16 16:39:00
合計ジャッジ時間 9,389 ms
ジャッジサーバーID
(参考情報)
judge6 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 31 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

# coding: utf-8
import array, bisect, collections, heapq, itertools, math, random, re, string, sys, time

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7


def II(): return int(input())
def ILI(): return list(map(int, input().split()))
def IAI(LINE): return [ILI() for __ in range(LINE)]
def IDI(): return {key: value for key, value in ILI()}


def make_primes(num_from, num_to):
    primes = []

    for i in range(num_from, num_to + 1):
        bool_prime = True
        if i == 1:
            continue
        elif i == 2:
            primes.append(2)
            continue
        for j in range(2, math.ceil(math.sqrt(i)) + 1):
            if i % j == 0:
                bool_prime = False
                break
        if bool_prime:
            primes.append(i)

    return primes


def make_one_hash(num):
    num_list = list(map(int, list(str(num))))
    while len(num_list) != 1:
        hash_sum = sum(num_list)
        num_list = list(map(int, list(str(hash_sum))))

    return num_list[0]


def solve(K, N):
    primes = make_primes(K, N)
    prime_hash = list(map(make_one_hash, primes))
    left = 0

    max_num = 1
    ans = 0

    for right in range(1, len(prime_hash)):
        while prime_hash[right] in prime_hash[left: right]:
            left += 1
        if (right - left + 1) >= max_num:
            max_num = right - left + 1
            ans = primes[left]

    return ans


def main():
    K = II()
    N = II()
    print(solve(K, N))


if __name__ == "__main__":
    main()
0