結果

問題 No.3365 Prefix and Suffix X
コンテスト
ユーザー sasa8uyauya
提出日時 2025-11-22 23:29:28
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 625 bytes
コンパイル時間 432 ms
コンパイル使用メモリ 82,716 KB
実行使用メモリ 86,264 KB
最終ジャッジ日時 2025-11-22 23:30:20
合計ジャッジ時間 51,894 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 5 WA * 25
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

q=[[-1]*1000 for i in range(1000)]
for M in range(1000):
  for i in range(1000):
    j=(M*i)%1000
    if q[M][j]==-1:
      q[M][j]=M*i

T=int(input())
for _ in range(T):
  X,M=map(int,input().split())
  ans=-1
  for i in range(20):
    Y=X*(10**i)
    Y+=(-Y)%M
    Y+=q[M%1000][(X-Y)%1000]
    lx=len(str(X))
    ly=len(str(Y))
    if Y%M==0 and lx<=ly<=18 and str(Y)[:lx]==str(Y)[-lx:]==str(X):
      ans=Y
  for i in range(20):
    Y=(X-1)*(10**i)
    Y+=(-Y)%M
    Y+=q[M%1000][(X-Y)%1000]
    lx=len(str(X))
    ly=len(str(Y))
    if Y%M==0 and lx<=ly<=18 and str(Y)[:lx]==str(Y)[-lx:]==str(X):
      ans=Y
  print(ans)
0