結果

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

ソースコード

diff #
raw source code

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