結果

問題 No.2649 [Cherry 6th Tune C] Anthem Flower
ユーザー ゼットゼット
提出日時 2024-02-23 21:59:21
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,039 ms / 2,000 ms
コード長 798 bytes
コンパイル時間 259 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 82,936 KB
最終ジャッジ日時 2024-02-23 22:00:12
合計ジャッジ時間 11,199 ms
ジャッジサーバーID
(参考情報)
judge16 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,460 KB
testcase_01 AC 873 ms
77,508 KB
testcase_02 AC 817 ms
76,888 KB
testcase_03 AC 857 ms
77,444 KB
testcase_04 AC 852 ms
77,764 KB
testcase_05 AC 1,039 ms
77,228 KB
testcase_06 AC 999 ms
77,132 KB
testcase_07 AC 185 ms
77,340 KB
testcase_08 AC 180 ms
77,328 KB
testcase_09 AC 125 ms
76,560 KB
testcase_10 AC 122 ms
76,564 KB
testcase_11 AC 48 ms
62,112 KB
testcase_12 AC 48 ms
62,108 KB
testcase_13 AC 93 ms
80,980 KB
testcase_14 AC 77 ms
79,316 KB
testcase_15 AC 99 ms
79,184 KB
testcase_16 AC 93 ms
80,912 KB
testcase_17 AC 95 ms
81,820 KB
testcase_18 AC 106 ms
81,352 KB
testcase_19 AC 100 ms
81,236 KB
testcase_20 AC 85 ms
82,920 KB
testcase_21 AC 109 ms
81,268 KB
testcase_22 AC 107 ms
82,620 KB
testcase_23 AC 62 ms
77,552 KB
testcase_24 AC 60 ms
77,552 KB
testcase_25 AC 77 ms
82,932 KB
testcase_26 AC 59 ms
77,552 KB
testcase_27 AC 77 ms
82,932 KB
testcase_28 AC 77 ms
82,936 KB
testcase_29 AC 79 ms
82,936 KB
testcase_30 AC 59 ms
77,552 KB
testcase_31 AC 78 ms
82,932 KB
testcase_32 AC 77 ms
82,936 KB
testcase_33 AC 78 ms
82,936 KB
testcase_34 AC 775 ms
76,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

Q=int(input())
for _ in range(Q):
  S,M=input().split()
  M=int(M)
  N=len(S)
  u=[1]*N
  mod=M
  if M==1:
    print(0)
    continue
  for i in range(1,N):
    u[i]=u[i-1]*10
    u[i]%=mod
  x=0
  for i in range(N):
    x+=int(S[-(i+1)])*u[i]
    x%=mod
  if M%2==1:
    result=x*(x+1)
    result%=mod
    result*=pow(2,-1,mod)
    result%=mod
    print(result)
  else:
    result=x*(x+1)//2
    result%=mod
    if (x+1)%mod==0:
      result=0
    u2=[1]*N
    mod2=2*M
    for i in range(1,N):
      u2[i]=u2[i-1]*10
      u2[i]%=mod2
    z=0
    for i in range(N):
      z+=int(S[-(i+1)])*u2[i]
      z%=mod2
    if x%2==0:
      if z!=x:
        result+=(M//2)*(x+1)
        result%=mod
    else:
      if ((z+1)%mod2)!=((x+1)%mod):
        result+=(M//2)*x
        result%=mod
    print(result)
0