結果

問題 No.3365 Prefix and Suffix X
コンテスト
ユーザー 回転
提出日時 2025-11-17 23:44:18
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,078 bytes
コンパイル時間 236 ms
コンパイル使用メモリ 82,240 KB
実行使用メモリ 68,556 KB
最終ジャッジ日時 2025-11-17 23:44:23
合計ジャッジ時間 4,175 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other RE * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

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

    ans = -1
    for keta in range(len(X),19):
        tmp = ["_"] * keta
        for i in range(len(X)):
            tmp[i] = X[i]
            tmp[-i-1] = X[len(X)-1-i]
        tmp = "".join(tmp)
        if not (tmp.startswith(X) and tmp.endswith(X)):continue
        
        if("_" not in tmp):
            if(int(tmp)%M == 0):
                ans = int(tmp)
                break
            continue
        
        MOD = (int(X) + int(X) * 10**(keta - len(X))) % M
        nokori = (M - MOD) % M
        if(nokori == 0):
            ans = int(tmp.replace("_","0"))
            break
        elif(nokori%10 != 0):
            continue
        
        if(pow(10,len(X),M) == 0):continue
        MIN = 0 * 10**len(X)
        MAX = 10**(keta - 2*len(X)) - 1

        x = nokori * pow(10,-len(X),M) % M
        if(x > MAX):continue
        
        length = tmp.count("_")
        new = "0" * (length - len(str(x))) +  str(x)
        ans = tmp.replace("_"*length,new)
        break

    print(ans)
0