結果

問題 No.3365 Prefix and Suffix X
コンテスト
ユーザー Koi
提出日時 2025-10-29 18:13:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 400 ms / 2,000 ms
コード長 774 bytes
コンパイル時間 207 ms
コンパイル使用メモリ 82,644 KB
実行使用メモリ 85,612 KB
最終ジャッジ日時 2025-11-17 20:40:07
合計ジャッジ時間 17,376 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

L = [[-1] * 1000 for _ in range(1000)]
for i in range(1000):
    x = 0
    for j in range(1000):
        if(L[i][x % 1000] == -1):
            L[i][x % 1000] = j
        if(L[i][x % 100] == -1):
            L[i][x % 100] = j
        if(L[i][x % 10] == -1):
            L[i][x % 10] = j
        x += i
def solve(X, M):
    if(L[M%1000][X] == -1):
        return -1
    else:
        f = (X + 1) * 10 ** 10 - 9 * 10 ** 9
        f -= f % M
        ans = str(f * 1000 + M * L[M % 1000][X])
        assert(len(str(X)) <= len(ans) <= 18)
        assert(int(ans) % M == 0)
        assert(ans[:len(str(X))] == str(X))
        assert(ans[-len(str(X)):] == str(X))
        return ans

T = int(input())
for _ in range(T):
    X, M = map(int, input().split())
    print(solve(X, M))

0