結果

問題 No.6 使いものにならないハッシュ
ユーザー sue_charosue_charo
提出日時 2017-04-27 14:42:36
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,517 bytes
コンパイル時間 67 ms
コンパイル使用メモリ 10,940 KB
実行使用メモリ 10,804 KB
最終ジャッジ日時 2023-10-14 23:05:19
合計ジャッジ時間 8,842 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
9,980 KB
testcase_01 AC 31 ms
10,012 KB
testcase_02 AC 507 ms
10,804 KB
testcase_03 AC 75 ms
10,152 KB
testcase_04 AC 106 ms
10,228 KB
testcase_05 AC 124 ms
10,252 KB
testcase_06 AC 261 ms
10,396 KB
testcase_07 AC 158 ms
10,240 KB
testcase_08 AC 234 ms
10,324 KB
testcase_09 AC 108 ms
10,060 KB
testcase_10 WA -
testcase_11 AC 81 ms
10,164 KB
testcase_12 AC 304 ms
10,552 KB
testcase_13 AC 73 ms
10,056 KB
testcase_14 AC 107 ms
10,080 KB
testcase_15 AC 245 ms
10,328 KB
testcase_16 AC 191 ms
10,228 KB
testcase_17 AC 384 ms
10,596 KB
testcase_18 AC 477 ms
10,552 KB
testcase_19 AC 367 ms
10,612 KB
testcase_20 AC 309 ms
10,400 KB
testcase_21 AC 54 ms
10,040 KB
testcase_22 AC 343 ms
10,464 KB
testcase_23 AC 301 ms
10,496 KB
testcase_24 AC 323 ms
10,540 KB
testcase_25 AC 182 ms
10,236 KB
testcase_26 AC 405 ms
10,504 KB
testcase_27 AC 302 ms
10,348 KB
testcase_28 AC 175 ms
10,268 KB
testcase_29 AC 426 ms
10,728 KB
testcase_30 AC 361 ms
10,556 KB
testcase_31 AC 333 ms
10,416 KB
権限があれば一括ダウンロードができます

ソースコード

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