結果

問題 No.8015 アンチローリングハッシュ
ユーザー norioc
提出日時 2025-03-23 22:33:57
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 72 ms / 2,000 ms
コード長 442 bytes
コンパイル時間 505 ms
コンパイル使用メモリ 82,832 KB
実行使用メモリ 72,568 KB
最終ジャッジ日時 2025-03-23 22:34:00
合計ジャッジ時間 3,726 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

from string import ascii_lowercase
import random


def myhash(s: str, b, mod):
    h = 0
    for c in s:
        h = h*b + ord(c)
        h %= mod

    return h


def gen_str(n: int) -> str:
    return ''.join(random.choices(ascii_lowercase, k=n))


A, B = map(int, input().split())

used = {}
k = 50
while 1:
    s = gen_str(k)
    h = myhash(s, A, B)
    if h in used:
        print(s)
        print(used[h])
        break

    used[h] = s
0