結果

問題 No.6 使いものにならないハッシュ
ユーザー yuki2006yuki2006
提出日時 2014-10-04 02:58:41
言語 Python2
(2.7.18)
結果
AC  
実行時間 91 ms / 5,000 ms
コード長 1,110 bytes
コンパイル時間 694 ms
コンパイル使用メモリ 6,696 KB
実行使用メモリ 7,860 KB
最終ジャッジ日時 2023-10-14 22:45:53
合計ジャッジ時間 3,562 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
5,952 KB
testcase_01 AC 11 ms
5,952 KB
testcase_02 AC 91 ms
7,828 KB
testcase_03 AC 24 ms
6,212 KB
testcase_04 AC 36 ms
6,580 KB
testcase_05 AC 34 ms
6,168 KB
testcase_06 AC 60 ms
7,120 KB
testcase_07 AC 52 ms
7,168 KB
testcase_08 AC 60 ms
7,244 KB
testcase_09 AC 70 ms
7,800 KB
testcase_10 AC 11 ms
5,928 KB
testcase_11 AC 25 ms
6,148 KB
testcase_12 AC 63 ms
7,052 KB
testcase_13 AC 62 ms
7,804 KB
testcase_14 AC 65 ms
7,832 KB
testcase_15 AC 55 ms
7,068 KB
testcase_16 AC 66 ms
7,616 KB
testcase_17 AC 81 ms
7,828 KB
testcase_18 AC 87 ms
7,784 KB
testcase_19 AC 78 ms
7,860 KB
testcase_20 AC 66 ms
7,572 KB
testcase_21 AC 19 ms
5,964 KB
testcase_22 AC 73 ms
7,776 KB
testcase_23 AC 63 ms
7,200 KB
testcase_24 AC 69 ms
7,580 KB
testcase_25 AC 54 ms
7,088 KB
testcase_26 AC 79 ms
7,696 KB
testcase_27 AC 71 ms
7,600 KB
testcase_28 AC 45 ms
6,808 KB
testcase_29 AC 81 ms
7,860 KB
testcase_30 AC 72 ms
7,620 KB
testcase_31 AC 70 ms
7,508 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

K = int(raw_input())
N = int(raw_input())


def foldnum(n):
    if n == 0:
        return 0
    if n % 9 == 0:
        return 9
    return n % 9


def eratos(n):
    list = xrange(2, n + 1)
    ans = []
    while len(list):
        ans.append(list[0])
        list = filter(lambda x: x % list[0] > 0, list)
    return ans


def eratos2(n):
    table = [True] * (n + 1)
    table[0] = table[1] = False
    a = 2
    while a * a <= n:
        if table[a]:
            k = 2
            while a * k <= n:
                table[a * k] = False
                k += 1
        a += 1
    ans = []
    for i, v in enumerate(table):
        if v:
            ans.append(i)
    return ans


prime_map = filter(lambda x: x >= K, eratos2(N))
L = len(prime_map)
a = 0
b = 0
mx = 0
total = 0
check = [False] * 10
maxIndex = 0
while a < L:
    while b < L:
        v = foldnum(prime_map[b])
        if check[v]:
            break
        b += 1
        check[v] = True
    if mx <= b - a - 1:
        mx = b - a - 1
        maxIndex = a
    v = foldnum(prime_map[a])
    check[v] = False
    a += 1
print prime_map[maxIndex]
0