結果

問題 No.1252 数字根D
ユーザー 👑 rin204rin204
提出日時 2022-01-18 21:34:55
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 103 ms / 2,000 ms
コード長 559 bytes
コンパイル時間 301 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 76,672 KB
最終ジャッジ日時 2024-05-02 19:31:34
合計ジャッジ時間 2,081 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
52,224 KB
testcase_01 AC 44 ms
52,224 KB
testcase_02 AC 41 ms
52,736 KB
testcase_03 AC 65 ms
66,432 KB
testcase_04 AC 87 ms
76,544 KB
testcase_05 AC 102 ms
76,396 KB
testcase_06 AC 88 ms
76,288 KB
testcase_07 AC 89 ms
76,076 KB
testcase_08 AC 89 ms
76,672 KB
testcase_09 AC 91 ms
76,672 KB
testcase_10 AC 85 ms
76,436 KB
testcase_11 AC 103 ms
76,268 KB
testcase_12 AC 95 ms
76,544 KB
testcase_13 AC 87 ms
76,672 KB
testcase_14 AC 39 ms
52,736 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve():
    g, a, b = map(int, input().split())
    if a == 0:
        if b == 0:
            print(0)
            return
        a = 1
    g -= 1
    ans = 0
    c = (a - 1) % g + 1
    d = (b - 1) % g + 1
    if d >= c:
        ans += (d + c) * (d - c + 1) // 2
        l = (b - a + 1) - (d - c + 1)
        l //= g
    else:
        ans += (1 + d) * d // 2
        ans += (g + c) * (g - c + 1) // 2
        l = (b - a + 1) - d - (g - c + 1)
        l //= g
    ans += l * (1 + g) * g // 2
    print(ans)
    

for _ in range(int(input())):
    solve()
0