結果

問題 No.2649 [Cherry 6th Tune C] Anthem Flower
ユーザー FromBooskaFromBooska
提出日時 2024-02-24 07:09:46
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 648 ms / 2,000 ms
コード長 676 bytes
コンパイル時間 461 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 76,196 KB
最終ジャッジ日時 2024-02-24 07:09:56
合計ジャッジ時間 8,880 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,204 KB
testcase_01 AC 570 ms
75,600 KB
testcase_02 AC 595 ms
75,600 KB
testcase_03 AC 563 ms
75,600 KB
testcase_04 AC 594 ms
75,600 KB
testcase_05 AC 629 ms
75,600 KB
testcase_06 AC 648 ms
75,600 KB
testcase_07 AC 88 ms
75,600 KB
testcase_08 AC 87 ms
75,600 KB
testcase_09 AC 58 ms
68,560 KB
testcase_10 AC 58 ms
68,560 KB
testcase_11 AC 41 ms
59,580 KB
testcase_12 AC 41 ms
59,580 KB
testcase_13 AC 63 ms
75,992 KB
testcase_14 AC 62 ms
75,772 KB
testcase_15 AC 62 ms
75,468 KB
testcase_16 AC 65 ms
75,548 KB
testcase_17 AC 64 ms
75,840 KB
testcase_18 AC 62 ms
75,592 KB
testcase_19 AC 68 ms
75,596 KB
testcase_20 AC 62 ms
76,164 KB
testcase_21 AC 65 ms
75,804 KB
testcase_22 AC 65 ms
76,064 KB
testcase_23 AC 61 ms
76,196 KB
testcase_24 AC 59 ms
76,196 KB
testcase_25 AC 59 ms
76,196 KB
testcase_26 AC 60 ms
76,196 KB
testcase_27 AC 61 ms
76,196 KB
testcase_28 AC 59 ms
76,196 KB
testcase_29 AC 60 ms
76,196 KB
testcase_30 AC 60 ms
76,196 KB
testcase_31 AC 60 ms
76,196 KB
testcase_32 AC 59 ms
76,196 KB
testcase_33 AC 53 ms
60,856 KB
testcase_34 AC 557 ms
75,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# Mは素数とは限らないので逆元を求めるのは面倒
# Nは超巨大数がありうるが計算できるのか不明
# RE、やっぱり超巨大数は文字列で受けるしかない
# 公式解説見た
# N(N+1)//2=Mq+r, N(N+1)=2Mq+2r, K=N%(2M)として計算
# Nは超巨大数なので筆算のように上の桁から割り算して10倍してを繰り返す

T = int(input())
for t in range(T):
    N, M = map(str, input().split())
    M = int(M)
    K = 0
    for n in N:
        K = (K*10+int(n))%(M*2)
        #print('K', K)
    ans2 = (K*(K+1))%(M*2)
    # このans2は偶数を偶数で割った余りなので偶数
    ans = ans2//2
    print(ans)
0