結果
| 問題 |
No.1252 数字根D
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-10-09 23:02:33 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 577 bytes |
| コンパイル時間 | 141 ms |
| コンパイル使用メモリ | 12,416 KB |
| 実行使用メモリ | 10,752 KB |
| 最終ジャッジ日時 | 2024-07-20 13:47:40 |
| 合計ジャッジ時間 | 1,455 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | WA * 14 |
ソースコード
t = int(input())
def digit_sum(x, d):
while x >= d:
tmp = 0
while x > 0:
tmp += x % d
x //= d
x = tmp
return x
for _ in range(t):
d, a, b = map(int, input().split())
left = digit_sum(a, d)
right = digit_sum(b, d)
one_cycle = (d - 1) * d // 2
cycle_len = d - 1
n = b - a + 1
ds = digit_sum(a, d)
ans = n // cycle_len * one_cycle
head = one_cycle - (left - 1) * left // 2 if left != 1 else 0
tail = right * (right + 1) // 2 if right < d - 1 else 0
print(ans + head + tail)